mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Replace legacy UA with hybrid Firefox/Chrome UA
This commit is contained in:
@@ -1,36 +1,30 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const PLATFORM_MAC = "Macintosh; Intel Mac OS X 10_14_1";
|
const PLATFORM_MAC = "Macintosh; Intel Mac OS X 10_15_2";
|
||||||
|
const PLATFORM_MAC_HYBRID = "Macintosh; Intel Mac OS X 10.15; rv:72.0";
|
||||||
const PLATFORM_WIN = "Windows NT 10.0; Win64; x64";
|
const PLATFORM_WIN = "Windows NT 10.0; Win64; x64";
|
||||||
const PLATFORM_LINUX = "Mozilla/5.0 (X11; Linux x86_64";
|
const PLATFORM_LINUX = "X11; Linux x86_64";
|
||||||
|
|
||||||
const UA_PREFIX = "Mozilla/5.0";
|
const UA_CHROME = "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36";
|
||||||
|
const UA_HYBRID = "Chrome/80.0.3987.87 Gecko/20100101 Firefox/72.0"
|
||||||
|
|
||||||
const UA_CHROME = "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36";
|
export function getChromeUserAgent(platform: string, hybrid = false) {
|
||||||
const UA_CHROME_LEGACY = "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2883.87 Safari/537.36";
|
let platformComponent: string;
|
||||||
const UA_SAFARI = "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15";
|
if (platform === "mac") {
|
||||||
|
platformComponent = hybrid
|
||||||
|
? PLATFORM_MAC_HYBRID
|
||||||
function getPlatformComponent (platform: string): string | undefined {
|
: PLATFORM_MAC;
|
||||||
switch (platform) {
|
} else if (platform === "win") {
|
||||||
case "mac": return PLATFORM_MAC; break;
|
platformComponent = PLATFORM_WIN;
|
||||||
case "win": return PLATFORM_WIN; break;
|
} else if (platform === "linux") {
|
||||||
case "linux": return PLATFORM_LINUX; break;
|
platformComponent = PLATFORM_LINUX;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function getChromeUserAgent (
|
const browserComponent = hybrid
|
||||||
platform: string
|
? UA_HYBRID
|
||||||
, legacy: boolean = false): string {
|
|
||||||
|
|
||||||
const platformComponent = getPlatformComponent(platform);
|
|
||||||
const browserComponent = legacy
|
|
||||||
? UA_CHROME_LEGACY
|
|
||||||
: UA_CHROME;
|
: UA_CHROME;
|
||||||
|
|
||||||
return `${UA_PREFIX} (${platformComponent}) ${browserComponent}`;
|
return `Mozilla/5.0 (${platformComponent}) ${browserComponent}`;
|
||||||
}
|
|
||||||
|
|
||||||
export function getSafariUserAgent (): string {
|
|
||||||
return `${UA_PREFIX} (${PLATFORM_MAC}) ${UA_SAFARI}`;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user