e833b923c8
接入 Playwright Worker、会话 WebSocket 与全局浏览器面板(固定于 App Bar 下); 含验证码 stealth、设置项默认音与 URL 安全校验;附带 worker 部署与设计文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Reduce automation fingerprints for sites with CAPTCHA (e.g. 阿里云)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
CHROMIUM_ARGS = [
|
|
"--disable-blink-features=AutomationControlled",
|
|
"--no-sandbox",
|
|
"--disable-dev-shm-usage",
|
|
"--disable-infobars",
|
|
"--window-position=0,0",
|
|
"--lang=zh-CN",
|
|
]
|
|
|
|
# Playwright adds --enable-automation by default; drop it for CAPTCHA sites.
|
|
IGNORE_DEFAULT_ARGS = ["--enable-automation"]
|
|
|
|
STEALTH_INIT_SCRIPT = """
|
|
(() => {
|
|
Object.defineProperty(navigator, 'webdriver', { get: () => undefined, configurable: true });
|
|
Object.defineProperty(navigator, 'languages', { get: () => ['zh-CN', 'zh', 'en-US', 'en'] });
|
|
Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5] });
|
|
const originalQuery = window.navigator.permissions.query;
|
|
window.navigator.permissions.query = (parameters) => (
|
|
parameters.name === 'notifications'
|
|
? Promise.resolve({ state: Notification.permission })
|
|
: originalQuery(parameters)
|
|
);
|
|
window.chrome = window.chrome || { runtime: {} };
|
|
})();
|
|
"""
|
|
|
|
DEFAULT_USER_AGENT = (
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
)
|
|
|
|
CONTEXT_OPTIONS = {
|
|
"user_agent": DEFAULT_USER_AGENT,
|
|
"locale": "zh-CN",
|
|
"timezone_id": "Asia/Shanghai",
|
|
"color_scheme": "light",
|
|
"device_scale_factor": 1,
|
|
"has_touch": False,
|
|
"is_mobile": False,
|
|
"java_script_enabled": True,
|
|
}
|