17 lines
866 B
TypeScript
17 lines
866 B
TypeScript
import { randomInt } from 'node:crypto';
|
|
import { getOrCreateSetting } from './db';
|
|
|
|
// Desktop Windows browser profiles. Choose a browser once per instance, not
|
|
// once per request, so HTTP calls and socket reconnects keep the same identity.
|
|
const USER_AGENTS = [
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36',
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0',
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
|
] as const;
|
|
|
|
const g = globalThis as typeof globalThis & { __requestUserAgent?: string };
|
|
|
|
export function getRequestUserAgent(): string {
|
|
return g.__requestUserAgent ??= getOrCreateSetting('user_agent', () => USER_AGENTS[randomInt(USER_AGENTS.length)]);
|
|
}
|