@@ -15,39 +15,53 @@ var UAHelpers = {
1515 return `FxQuantum/${ UAHelpers . getRunningFirefoxVersion ( ) } ` ;
1616 } ,
1717 getDeviceAppropriateChromeUA ( config = { } ) {
18- const { version = "130.0.0.0" , androidDevice , desktopOS } = config ;
19- const key = ` ${ version } : ${ androidDevice } : ${ desktopOS } ` ;
20- if ( ! UAHelpers . _deviceAppropriateChromeUAs [ key ] ) {
18+ let { androidVersion , version = "130.0.0.0" , phone , tablet , OS } = config ;
19+ const key = JSON . stringify ( config ) ;
20+ if ( config . noCache || ! UAHelpers . _deviceAppropriateChromeUAs [ key ] ) {
2121 const userAgent =
2222 config . ua ||
2323 ( typeof navigator !== "undefined" ? navigator . userAgent : "" ) ;
2424 const fxQuantum = config . noFxQuantum
2525 ? ""
2626 : UAHelpers . getFxQuantumSegment ( ) ;
27- if ( userAgent . includes ( "Android" ) ) {
28- const RunningAndroidVersion =
29- userAgent . match ( / A n d r o i d [ 0 - 9 . ] + / ) || "Android 6.0" ;
30- if ( androidDevice ) {
27+ const noOSGiven = ! OS || OS === "nonLinux" ;
28+ if ( OS === "android" || ( noOSGiven && userAgent . includes ( "Android" ) ) ) {
29+ const AndroidVersion = androidVersion
30+ ? `Android ${ androidVersion } `
31+ : userAgent . match ( / A n d r o i d [ 0 - 9 . ] + / ) || "Android 6.0" ;
32+ if ( phone === undefined && tablet === undefined ) {
33+ phone = userAgent . includes ( "Mobile" ) ;
34+ tablet = userAgent . includes ( "Tablet" ) ;
35+ }
36+ if ( phone === true ) {
37+ phone = "Nexus 5 Build/MRA58N" ;
38+ }
39+ if ( tablet === true || ( ! tablet && ! phone ) ) {
40+ tablet = "Nexus 7 Build/JSS15Q" ;
41+ }
42+ if ( phone ) {
3143 UAHelpers . _deviceAppropriateChromeUAs [ key ] =
32- `Mozilla/5.0 (Linux; ${ RunningAndroidVersion } ; ${ androidDevice } ) ${ fxQuantum } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Mobile Safari/537.36` ;
44+ `Mozilla/5.0 (Linux; ${ AndroidVersion } ; ${ phone } ) ${ fxQuantum } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Mobile Safari/537.36` ;
3345 } else {
34- const ChromePhoneUA = `Mozilla/5.0 (Linux; ${ RunningAndroidVersion } ; Nexus 5 Build/MRA58N) ${ fxQuantum } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Mobile Safari/537.36` ;
35- const ChromeTabletUA = `Mozilla/5.0 (Linux; ${ RunningAndroidVersion } ; Nexus 7 Build/JSS15Q) ${ fxQuantum } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Safari/537.36` ;
36- const IsPhone = userAgent . includes ( "Mobile" ) ;
37- UAHelpers . _deviceAppropriateChromeUAs [ key ] = IsPhone
38- ? ChromePhoneUA
39- : ChromeTabletUA ;
46+ UAHelpers . _deviceAppropriateChromeUAs [ key ] =
47+ `Mozilla/5.0 (Linux; ${ AndroidVersion } ; ${ tablet } ) ${ fxQuantum } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Safari/537.36` ;
4048 }
4149 } else {
42- let osSegment = "Windows NT 10.0; Win64; x64" ;
43- if ( desktopOS === "macOS" || userAgent . includes ( "Macintosh" ) ) {
50+ const WIN_SEGMENT = "Windows NT 10.0; Win64; x64" ;
51+ let osSegment ;
52+ if ( OS === "macOS" || ( noOSGiven && userAgent . includes ( "Macintosh" ) ) ) {
4453 osSegment = "Macintosh; Intel Mac OS X 10_15_7" ;
45- }
46- if (
47- desktopOS !== "nonLinux" &&
48- ( desktopOS === "linux" || userAgent . includes ( "Linux" ) )
54+ } else if (
55+ OS === "linux" ||
56+ ( noOSGiven && userAgent . includes ( "Linux" ) )
4957 ) {
50- osSegment = "X11; Ubuntu; Linux x86_64" ;
58+ if ( OS !== "nonLinux" ) {
59+ osSegment = "X11; Ubuntu; Linux x86_64" ;
60+ } else {
61+ osSegment = WIN_SEGMENT ;
62+ }
63+ } else {
64+ osSegment = WIN_SEGMENT ;
5165 }
5266
5367 UAHelpers . _deviceAppropriateChromeUAs [ key ] =
@@ -110,9 +124,6 @@ var UAHelpers = {
110124
111125 return ua ;
112126 } ,
113- firefoxPlusChrome ( ua = navigator . userAgent , version = "130.0.0.0" ) {
114- return `${ ua } AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ version } Mobile Safari/537.36` ;
115- } ,
116127 getPrefix ( originalUA ) {
117128 return originalUA . substr ( 0 , originalUA . indexOf ( ")" ) + 1 ) ;
118129 } ,
0 commit comments