Created
May 1, 2020 00:11
-
-
Save ps-jessejjohnson/8622c5c3fdc6213a89ca0da20687d3f3 to your computer and use it in GitHub Desktop.
Set User-Agent header with Puppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sourced from @ps-anthonymcnamara intelligence