Skip to content

Instantly share code, notes, and snippets.

@endel
Created September 13, 2018 23:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endel/b75d3a6af0fcae066dfa09cc066f56ee to your computer and use it in GitHub Desktop.
Save endel/b75d3a6af0fcae066dfa09cc066f56ee to your computer and use it in GitHub Desktop.
Fake User Agent Generator
export function* generateUserAgent() {
let webkitVersion = 10;
let chromeVersion = 1000;
const so = [
'Windows NT 6.1; WOW64',
'Windows NT 6.2; Win64; x64',
"Windows NT 5.1; Win64; x64",,
'Macintosh; Intel Mac OS X 10_12_6',
"X11; Linux x86_64",
"X11; Linux armv7l"
];
let soIndex = Math.floor(Math.random() * so.length);
while (true) {
yield `Mozilla/5.0 (${so[soIndex++ % so.length]}) AppleWebKit/537.${webkitVersion} (KHTML, like Gecko) Chrome/56.0.${chromeVersion}.87 Safari/537.${webkitVersion} OPR/43.0.2442.991`;
webkitVersion++;
chromeVersion++;
}
}
@ilyazub
Copy link

ilyazub commented Apr 9, 2021

Cool! @endel, have you compared the generated strings to the actual browser user agents?

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