Skip to content

Instantly share code, notes, and snippets.

@ps-jessejjohnson
Created May 1, 2020 00:11
Show Gist options
  • Save ps-jessejjohnson/8622c5c3fdc6213a89ca0da20687d3f3 to your computer and use it in GitHub Desktop.
Save ps-jessejjohnson/8622c5c3fdc6213a89ca0da20687d3f3 to your computer and use it in GitHub Desktop.
Set User-Agent header with Puppeteer
// Intellectual genuineness of
// Anthony McNamara (aka Big Red)
// Great article regarding approach
// https://medium.com/@filipvitas/how-to-set-user-agent-header-with-puppeteer-js-and-not-fail-28c7a02165da
Object.defineProperty(navigator, 'Mozilla/5.0 (compatible; PriceSpider0.2; +https://www.pricespider.com/)', {
get: function() { return setPlat },
set: function(a) { }
});
var setPlat;
var plat = navigator.userAgent.match(/Mozilla\/5\.0\s*\((Windows|Macintosh|iPhone|Linux|compatible)/i)[1];
if (plat == "Windows" || plat == "compatible") {
setPlat = "Win32";
} else if (plat == "Macintosh" || plat == "iPhone" || plat == "Linux") {
setPlat = "MacIntel";
}
try {
Object.defineProperty(navigator, 'platform', {
get: function() { return setPlat },
set: function(a) { }
});
Object.defineProperty(navigator, 'hardwareConcurrency', {
get: function() { return 12 },
set: function(a) { }
});
true;
} catch (err) {
false;
}
@ps-jessejjohnson
Copy link
Author

sourced from @ps-anthonymcnamara intelligence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment