49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
/**
|
|
* 统一浏览器指纹与请求头生成器
|
|
* 用于防范 WAF 拦截 (如 CloudWAF 418/403) 及统一 Web 会话环境
|
|
*/
|
|
|
|
export interface BrowserFingerprintOptions {
|
|
/** 自定义 Cookie 字符串 */
|
|
cookie?: string;
|
|
/** 自定义 Referer 来源 (默认 https://app.ekuaibao.com/) */
|
|
referer?: string;
|
|
/** 自定义 Origin 域 (默认 https://app.ekuaibao.com) */
|
|
origin?: string;
|
|
/** 是否禁用 Sec-Ch-Ua 等客户端提示头 (默认 false) */
|
|
disableClientHints?: boolean;
|
|
}
|
|
|
|
export const DEFAULT_USER_AGENT =
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
|
|
|
export const DEFAULT_REFERER = "https://app.ekuaibao.com/";
|
|
export const DEFAULT_ORIGIN = "https://app.ekuaibao.com";
|
|
|
|
/**
|
|
* 获取伪装现代浏览器的标准指纹请求头
|
|
*/
|
|
export function getBrowserFingerprintHeaders(
|
|
options: BrowserFingerprintOptions = {}
|
|
): Record<string, string> {
|
|
const headers: Record<string, string> = {
|
|
"User-Agent": DEFAULT_USER_AGENT,
|
|
Accept: "application/json, text/plain, */*",
|
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
Referer: options.referer ?? DEFAULT_REFERER,
|
|
Origin: options.origin ?? DEFAULT_ORIGIN,
|
|
};
|
|
|
|
if (!options.disableClientHints) {
|
|
headers["sec-ch-ua"] = '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"';
|
|
headers["sec-ch-ua-mobile"] = "?0";
|
|
headers["sec-ch-ua-platform"] = '"macOS"';
|
|
}
|
|
|
|
if (options.cookie && options.cookie.trim()) {
|
|
headers["Cookie"] = options.cookie.trim();
|
|
}
|
|
|
|
return headers;
|
|
}
|