diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/userAgent-helpers.js | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js index fc9a6f507..4aa6f92d0 100644 --- a/src/helpers/userAgent-helpers.js +++ b/src/helpers/userAgent-helpers.js | |||
@@ -1,29 +1,35 @@ | |||
1 | import os from 'os'; | 1 | import os from 'os'; |
2 | import macosVersion from 'macos-version'; | 2 | import macosVersion from 'macos-version'; |
3 | import { | 3 | import { chromeVersion, isMac, isWindows } from '../environment'; |
4 | ferdiVersion, electronVersion, chromeVersion, isMac, isWindows, | 4 | |
5 | } from '../environment'; | 5 | const uaGenerator = require('useragent-generator'); |
6 | |||
7 | function is64Bit() { | ||
8 | return os.arch().match(/64/); | ||
9 | } | ||
6 | 10 | ||
7 | function macOS() { | 11 | function macOS() { |
8 | const version = macosVersion(); | 12 | const version = macosVersion(); |
9 | return `Macintosh; Intel Mac OS X ${version.replace(/\./g, '_')}`; | 13 | let cpuName = os.cpus()[0].model.split(' ')[0]; |
14 | if (cpuName && cpuName.match(/\(/)) { | ||
15 | cpuName = cpuName.split('(')[0]; | ||
16 | } | ||
17 | return `Macintosh; ${cpuName} Mac OS X ${version.replace(/\./g, '_')}`; | ||
10 | } | 18 | } |
11 | 19 | ||
12 | function windows() { | 20 | function windows() { |
13 | const version = os.release(); | 21 | const version = os.release(); |
14 | const [majorVersion, minorVersion] = version.split('.'); | 22 | const [majorVersion, minorVersion] = version.split('.'); |
15 | return `Windows NT ${majorVersion}.${minorVersion}; Win64; x64`; | 23 | const archString = is64Bit() ? 'Win64' : 'Win32'; |
24 | return `Windows NT ${majorVersion}.${minorVersion}; ${archString}; ${os.arch()}`; | ||
16 | } | 25 | } |
17 | 26 | ||
18 | function linux() { | 27 | function linux() { |
19 | return 'X11; Ubuntu; Linux x86_64'; | 28 | const archString = is64Bit() ? 'x86_64' : os.arch(); |
20 | } | 29 | return `X11; Ubuntu; Linux ${archString}`; |
21 | |||
22 | export function isChromeless(url) { | ||
23 | return url.startsWith('https://accounts.google.com'); | ||
24 | } | 30 | } |
25 | 31 | ||
26 | export default function userAgent(removeChromeVersion = false, addFerdiVersion = false) { | 32 | export default function userAgent() { |
27 | let platformString = ''; | 33 | let platformString = ''; |
28 | 34 | ||
29 | if (isMac) { | 35 | if (isMac) { |
@@ -34,17 +40,5 @@ export default function userAgent(removeChromeVersion = false, addFerdiVersion = | |||
34 | platformString = linux(); | 40 | platformString = linux(); |
35 | } | 41 | } |
36 | 42 | ||
37 | let chromeVersionString = 'Chrome'; | 43 | return uaGenerator.chrome({ os: platformString, version: chromeVersion }); |
38 | if (!removeChromeVersion) { | ||
39 | chromeVersionString = `Chrome/${chromeVersion}`; | ||
40 | } | ||
41 | |||
42 | let applicationString = ''; | ||
43 | if (addFerdiVersion) { | ||
44 | applicationString = ` Ferdi/${ferdiVersion} Electron/${electronVersion}`; | ||
45 | } | ||
46 | |||
47 | // Chrome is pinned to WebKit 537.36, the latest version before hard forking to Blink. | ||
48 | return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) ${chromeVersionString} Safari/537.36${applicationString}`; | ||
49 | // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 Ferdi/5.5.1-nightly.13 Electron/8.2.3 | ||
50 | } | 44 | } |