Add periodic user agent string updates

This commit is contained in:
hensm
2025-12-27 02:13:57 +00:00
parent 50851b4831
commit 1f200bef9a
7 changed files with 131 additions and 27 deletions

View File

@@ -12,6 +12,7 @@ import deviceManager from "./deviceManager";
import { initAction } from "./action";
import { initMenus } from "./menus";
import { initWhitelist } from "./whitelist";
import { cacheUaInfo, getChromeUserAgentString } from "../lib/userAgents";
const _ = browser.i18n.getMessage;
@@ -143,5 +144,6 @@ async function init() {
});
}
cacheUaInfo();
cacheBaseConfig();
init();

View File

@@ -1,7 +1,7 @@
import logger from "../lib/logger";
import options from "../lib/options";
import { getChromeUserAgent } from "../lib/userAgents";
import { cacheUaInfo, getChromeUserAgentString } from "../lib/userAgents";
import { RemoteMatchPattern } from "../lib/matchPattern";
import {
@@ -41,11 +41,17 @@ let customUserAgent: string | undefined;
export async function initWhitelist() {
logger.info("init (whitelist)");
await cacheUaInfo();
if (!platform) {
const browserInfo = await browser.runtime.getBrowserInfo();
// TODO: Allow hybrid UA to be configurable
platform = (await browser.runtime.getPlatformInfo()).os;
chromeUserAgent = getChromeUserAgent(platform);
chromeUserAgentHybrid = getChromeUserAgent(platform, true);
chromeUserAgent = await getChromeUserAgentString(platform);
chromeUserAgentHybrid = await getChromeUserAgentString(platform, {
hybridFirefoxVersion: browserInfo.version
});
if (!chromeUserAgent) {
throw logger.error("Failed to get Chrome UA string");
}