@capyclaw/browser-suite 0.1.2 → 0.2.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -5
- package/composition.lock.json +37 -25
- package/contract/browser-contract.json +484 -25
- package/cordis.patch.yml +3 -9
- package/dsh-suite.json +110 -82
- package/lib/index.mjs +1 -1
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +304 -0
- package/node_modules/@capyclaw/browser-skill-api/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-api/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-api/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-api/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/SKILL.md +85 -0
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +692 -0
- package/node_modules/@capyclaw/browser-skill-browser/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-browser/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-browser/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-browser/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-browser/skills/browser/SKILL.md +27 -0
- package/node_modules/@capyclaw/browser-skill-ops/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-ops/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-ops/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-ops/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-ops/skills/browser-ops/SKILL.md +63 -0
- package/node_modules/@capyclaw/browser-workbench/README.md +89 -0
- package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-workbench/demo/form.html +112 -0
- package/node_modules/@capyclaw/browser-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/browser-workbench/package.json +71 -0
- package/node_modules/@capyclaw/browser-workbench/plugin.mjs +1 -0
- package/node_modules/@capyclaw/browser-workbench/server/constants.mjs +16 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract-snapshots.mjs +81 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +24 -0
- package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +247 -0
- package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +2466 -0
- package/node_modules/@capyclaw/browser-workbench/server/governor.mjs +189 -0
- package/node_modules/@capyclaw/browser-workbench/server/http-utils.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/human.mjs +628 -0
- package/node_modules/@capyclaw/browser-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/input.mjs +154 -0
- package/node_modules/@capyclaw/browser-workbench/server/login-vault.mjs +109 -0
- package/node_modules/@capyclaw/browser-workbench/server/mcp/handler.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/mcp/instructions.mjs +31 -0
- package/node_modules/@capyclaw/browser-workbench/server/orphans.mjs +163 -0
- package/node_modules/@capyclaw/browser-workbench/server/relay.mjs +198 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +233 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/assets.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/mcp.mjs +17 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/workbench.mjs +33 -0
- package/node_modules/@capyclaw/browser-workbench/server/session-engines.mjs +223 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/contract.mjs +55 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/evaluate.mjs +36 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/index.mjs +26 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/interaction.mjs +215 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/navigation.mjs +35 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/screenshot.mjs +50 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/session.mjs +81 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/snapshot.mjs +30 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/tabs.mjs +35 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/define.mjs +5 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/output.mjs +30 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/ports.mjs +59 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/registry.mjs +17 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools.mjs +3 -0
- package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +305 -0
- package/node_modules/@capyclaw/browser-workbench/ui/app.js +447 -0
- package/node_modules/@capyclaw/browser-workbench/ui/index.html +46 -0
- package/node_modules/@capyclaw/browser-workbench/ui/style.css +144 -0
- package/node_modules/@capyclaw/document-workbench/README.md +125 -0
- package/node_modules/@capyclaw/document-workbench/package.json +44 -0
- package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
- package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
- package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
- package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
- package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
- package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
- package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
- package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
- package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
- package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +103 -0
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
- package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
- package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
- package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
- package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
- package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
- package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +158 -0
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
- package/package.json +31 -14
- package/services.json +1 -21
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拟人操作与反自动化指纹(纯函数 + 可注入 RNG,可单测)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要这层:
|
|
5
|
+
* - Playwright 的 click/type 是「机器节奏」:0ms 位移、0ms 按键间隔、固定延迟、
|
|
6
|
+
* 从元素正中心命中。风控(Cloudflare/DataDome/Akamai/reCAPTCHA)与行为模型看
|
|
7
|
+
* 的就是这些统计特征:轨迹是直线、速度恒定、按键间隔方差极小、没有过冲/修正。
|
|
8
|
+
* - 浏览器侧还有静态指纹:navigator.webdriver、缺失的 chrome.runtime、空 plugins、
|
|
9
|
+
* 被 CDP 打开过的痕迹、WebGL 厂商串与平台不一致。
|
|
10
|
+
*
|
|
11
|
+
* 这里只做「让自动化看起来像真人」的通用工程手段(业界公开做法:
|
|
12
|
+
* ghost-cursor 的贝塞尔 + 最小急动度 + 微颤、playwright-stealth 的指纹补丁、
|
|
13
|
+
* patchright 的 CDP 泄漏面收敛),不涉及破解验证码或绕过登录。
|
|
14
|
+
*
|
|
15
|
+
* 设计口径:
|
|
16
|
+
* - 全部纯函数,RNG 注入 → 测试可复现;引擎里用 mulberry32(seed)。
|
|
17
|
+
* - 节奏参数分档(fast/normal/careful),速度与拟真度可显式取舍。
|
|
18
|
+
* - 指纹补丁一次性注入(addInitScript),不额外开 CDP 会话。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/* --------------------------------------------------------------------------
|
|
22
|
+
* 随机数:可复现的 mulberry32 + 截断高斯
|
|
23
|
+
* ------------------------------------------------------------------------ */
|
|
24
|
+
|
|
25
|
+
/** 32 位种子 → [0,1) 伪随机序列(同一 seed 完全可复现,测试用)。 */
|
|
26
|
+
export function mulberry32(seed) {
|
|
27
|
+
let a = seed >>> 0
|
|
28
|
+
return function next() {
|
|
29
|
+
a = (a + 0x6D2B79F5) >>> 0
|
|
30
|
+
let t = a
|
|
31
|
+
t = Math.imul(t ^ (t >>> 15), t | 1)
|
|
32
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
|
33
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function clamp(value, min, max) {
|
|
38
|
+
return Math.min(max, Math.max(min, value))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 截断到 ±3σ 的高斯噪声:人的反应时间/按键间隔都是右偏分布,不是均匀分布。 */
|
|
42
|
+
export function gauss(rng, mean, sd) {
|
|
43
|
+
const u1 = Math.max(rng(), 1e-9)
|
|
44
|
+
const u2 = rng()
|
|
45
|
+
const z = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2)
|
|
46
|
+
return mean + clamp(z, -3, 3) * sd
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 区间内均匀整数。 */
|
|
50
|
+
export function randInt(rng, min, max) {
|
|
51
|
+
return Math.floor(min + rng() * (max - min + 1))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* --------------------------------------------------------------------------
|
|
55
|
+
* 节奏档位
|
|
56
|
+
* ------------------------------------------------------------------------ */
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* fast :明显像人但不是慢动作(默认)。按键 20–60ms/字符、点击按住 15–40ms。
|
|
60
|
+
* normal :常规打字速度(60–130ms/字符),适合需要过行为风控的站点。
|
|
61
|
+
* careful:慢速谨慎操作(120–260ms/字符),带少量打错回退。
|
|
62
|
+
* off :完全机器节奏(最快,~5–20ms/动作),仅用于速度优先/内部基准。
|
|
63
|
+
*/
|
|
64
|
+
export const HUMAN_PROFILES = Object.freeze({
|
|
65
|
+
fast: {
|
|
66
|
+
name: 'fast',
|
|
67
|
+
/* 无头里每个 mouse.move / waitForTimeout 都要等一个渲染帧(实测 16.5ms),
|
|
68
|
+
所以 fast 档刻意压点数量与等待次数:3–4 个点仍是一条曲线,但不再为拟人白付 200ms。 */
|
|
69
|
+
reactionMs: [0, 5],
|
|
70
|
+
moveSteps: [3, 4],
|
|
71
|
+
curvature: 0.14,
|
|
72
|
+
jitterPx: 0.4,
|
|
73
|
+
holdMs: [1, 4],
|
|
74
|
+
typeMean: 0.35,
|
|
75
|
+
typeSd: 0.35,
|
|
76
|
+
typeMin: 0,
|
|
77
|
+
typeMax: 3,
|
|
78
|
+
/* 停顿是拟人里最贵的一项(一次停顿就是一帧 16ms),fast 档只保留偶发的「想一下」。 */
|
|
79
|
+
pauseChance: 0.12,
|
|
80
|
+
pauseMs: [1, 8],
|
|
81
|
+
typoRate: 0,
|
|
82
|
+
scrollSteps: [2, 2],
|
|
83
|
+
scrollIntervalMs: [0, 3],
|
|
84
|
+
pasteOverChars: 12,
|
|
85
|
+
/* fast 档轨迹一次批量送达(事件时间戳几乎相同):速度优先的取舍。
|
|
86
|
+
行为风控敏感的站点用 normal/careful——它们按真实时间间隔逐点发 mousemove。 */
|
|
87
|
+
pacedMoves: false,
|
|
88
|
+
moveMs: [0, 0],
|
|
89
|
+
dwellMs: [0, 0],
|
|
90
|
+
},
|
|
91
|
+
normal: {
|
|
92
|
+
name: 'normal',
|
|
93
|
+
reactionMs: [80, 260],
|
|
94
|
+
moveSteps: [12, 22],
|
|
95
|
+
curvature: 0.2,
|
|
96
|
+
jitterPx: 0.7,
|
|
97
|
+
holdMs: [45, 120],
|
|
98
|
+
typeMean: 92,
|
|
99
|
+
typeSd: 32,
|
|
100
|
+
typeMin: 25,
|
|
101
|
+
typeMax: 400,
|
|
102
|
+
pauseChance: 0.12,
|
|
103
|
+
pauseMs: [120, 420],
|
|
104
|
+
typoRate: 0.01,
|
|
105
|
+
scrollSteps: [3, 5],
|
|
106
|
+
scrollIntervalMs: [30, 90],
|
|
107
|
+
pasteOverChars: 120,
|
|
108
|
+
/* 逐点按最小急动度节奏发 mousemove:事件间隔 8–40ms,和真人手移动一致。
|
|
109
|
+
批量同帧送达的轨迹(时间戳全相同)是行为风控的显著机器特征。 */
|
|
110
|
+
pacedMoves: true,
|
|
111
|
+
moveMs: [240, 420],
|
|
112
|
+
/* 到达目标后、按下前的短暂停留:人眼确认落点再按。 */
|
|
113
|
+
dwellMs: [30, 90],
|
|
114
|
+
},
|
|
115
|
+
careful: {
|
|
116
|
+
name: 'careful',
|
|
117
|
+
reactionMs: [180, 560],
|
|
118
|
+
moveSteps: [18, 34],
|
|
119
|
+
curvature: 0.24,
|
|
120
|
+
jitterPx: 1,
|
|
121
|
+
holdMs: [70, 170],
|
|
122
|
+
typeMean: 185,
|
|
123
|
+
typeSd: 60,
|
|
124
|
+
typeMin: 50,
|
|
125
|
+
typeMax: 700,
|
|
126
|
+
pauseChance: 0.2,
|
|
127
|
+
pauseMs: [250, 900],
|
|
128
|
+
typoRate: 0.03,
|
|
129
|
+
scrollSteps: [4, 7],
|
|
130
|
+
scrollIntervalMs: [60, 160],
|
|
131
|
+
pasteOverChars: 200,
|
|
132
|
+
pacedMoves: true,
|
|
133
|
+
moveMs: [420, 720],
|
|
134
|
+
dwellMs: [60, 160],
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
/** 档位名 → 配置;'off'/未知 → null(调用方按机器节奏走)。 */
|
|
139
|
+
export function resolveHumanProfile(name) {
|
|
140
|
+
const key = String(name || '').trim().toLowerCase()
|
|
141
|
+
if (!key || key === 'off' || key === 'none' || key === 'false') return null
|
|
142
|
+
return HUMAN_PROFILES[key] || HUMAN_PROFILES.fast
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* --------------------------------------------------------------------------
|
|
146
|
+
* 鼠标轨迹
|
|
147
|
+
* ------------------------------------------------------------------------ */
|
|
148
|
+
|
|
149
|
+
/** 最小急动度(minimum jerk)时间规整:人的手臂起停是「慢-快-慢」。 */
|
|
150
|
+
export function minJerk(t) {
|
|
151
|
+
const x = clamp(t, 0, 1)
|
|
152
|
+
return x ** 3 * (10 - 15 * x + 6 * x * x)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function cubicAt(p0, p1, p2, p3, t) {
|
|
156
|
+
const u = 1 - t
|
|
157
|
+
return u * u * u * p0 + 3 * u * u * t * p1 + 3 * u * t * t * p2 + t * t * t * p3
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 两点的拟人轨迹:三次贝塞尔(控制点带随机侧向弯折)+ 最小急动度采样 +
|
|
162
|
+
* 高频微颤(越靠近终点越弱,模拟手眼修正收敛)。
|
|
163
|
+
* 返回不含起点的点列,终点精确等于 to。
|
|
164
|
+
*/
|
|
165
|
+
export function bezierPath(from, to, rng, profile = HUMAN_PROFILES.fast) {
|
|
166
|
+
const x0 = Number(from?.x) || 0
|
|
167
|
+
const y0 = Number(from?.y) || 0
|
|
168
|
+
const x1 = Number(to?.x) || 0
|
|
169
|
+
const y1 = Number(to?.y) || 0
|
|
170
|
+
const dist = Math.hypot(x1 - x0, y1 - y0)
|
|
171
|
+
const [minSteps, maxSteps] = profile?.moveSteps || [8, 14]
|
|
172
|
+
const steps = randInt(rng, minSteps, maxSteps)
|
|
173
|
+
/* 几乎不动的位移(元素正中心点击)不需要轨迹:人不挪鼠标也会点。 */
|
|
174
|
+
if (dist < 2) return [{ x: x1, y: y1 }]
|
|
175
|
+
const nx = -(y1 - y0) / dist
|
|
176
|
+
const ny = (x1 - x0) / dist
|
|
177
|
+
const curvature = Number(profile?.curvature) || 0.16
|
|
178
|
+
const bend1 = (rng() - 0.5) * 2 * curvature * dist
|
|
179
|
+
const bend2 = (rng() - 0.5) * 2 * curvature * dist
|
|
180
|
+
const c1 = { x: x0 + (x1 - x0) * (0.25 + rng() * 0.15) + nx * bend1, y: y0 + (y1 - y0) * (0.25 + rng() * 0.15) + ny * bend1 }
|
|
181
|
+
const c2 = { x: x0 + (x1 - x0) * (0.6 + rng() * 0.15) + nx * bend2, y: y0 + (y1 - y0) * (0.6 + rng() * 0.15) + ny * bend2 }
|
|
182
|
+
const amp = Number(profile?.jitterPx) || 0.5
|
|
183
|
+
const phase = rng() * Math.PI * 2
|
|
184
|
+
const points = []
|
|
185
|
+
for (let i = 1; i <= steps; i += 1) {
|
|
186
|
+
const t = minJerk(i / steps)
|
|
187
|
+
let x = cubicAt(x0, c1.x, c2.x, x1, t)
|
|
188
|
+
let y = cubicAt(y0, c1.y, c2.y, y1, t)
|
|
189
|
+
if (i < steps) {
|
|
190
|
+
/* 微颤:8–12Hz 生理抖动,按剩余进度衰减;只抖亚像素,不改命中点。 */
|
|
191
|
+
const wobble = Math.sin(t * Math.PI * 2 * (3 + rng()) + phase) * amp * (1 - t)
|
|
192
|
+
x += wobble
|
|
193
|
+
y += wobble * 0.6
|
|
194
|
+
}
|
|
195
|
+
points.push({ x: Math.round(x * 100) / 100, y: Math.round(y * 100) / 100 })
|
|
196
|
+
}
|
|
197
|
+
points[points.length - 1] = { x: x1, y: y1 }
|
|
198
|
+
return points
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 一次移动的总时长(Fitts 定律味道):距离越远耗时越长,但限制在合理倍率内。
|
|
203
|
+
* 返回 ms;profile.moveMs 是该档位的基准时长区间。
|
|
204
|
+
*/
|
|
205
|
+
export function moveDurationMs(dist, rng, profile = HUMAN_PROFILES.normal) {
|
|
206
|
+
const [lo, hi] = profile?.moveMs || [240, 420]
|
|
207
|
+
if (!(hi > 0)) return 0
|
|
208
|
+
const base = randInt(rng, lo, hi)
|
|
209
|
+
const scale = clamp(Math.log2(Math.max(Number(dist) || 0, 1) / 120 + 1), 0.55, 1.6)
|
|
210
|
+
return Math.round(base * scale)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 把总时长按最小急动度分配到轨迹各点:返回「发第 i 个点之前等多少 ms」。
|
|
215
|
+
* 起停慢、中段快,与 bezierPath 的采样同一时间规整——事件间隔因此和真人一致,
|
|
216
|
+
* 而不是 N 个 mousemove 挤在同一毫秒。总和 ≈ totalMs(取整误差 ±n/2 ms)。
|
|
217
|
+
*/
|
|
218
|
+
export function moveDelays(points, totalMs) {
|
|
219
|
+
const n = Array.isArray(points) ? points.length : 0
|
|
220
|
+
if (!n || !(totalMs > 0)) return new Array(n).fill(0)
|
|
221
|
+
const out = []
|
|
222
|
+
let prev = 0
|
|
223
|
+
for (let i = 1; i <= n; i += 1) {
|
|
224
|
+
const t = minJerk(i / n)
|
|
225
|
+
out.push(Math.max(0, Math.round((t - prev) * totalMs)))
|
|
226
|
+
prev = t
|
|
227
|
+
}
|
|
228
|
+
return out
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* --------------------------------------------------------------------------
|
|
232
|
+
* 打字节奏
|
|
233
|
+
* ------------------------------------------------------------------------ */
|
|
234
|
+
|
|
235
|
+
const SHIFT_HINTS = new Set(['@', '#', '$', '%', '&', '*', '(', ')', '_', '+', ':', '"', '<', '>', '?', '|', '~', '^', '{', '}', '!'])
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 打字计划:逐字符延迟(高斯抖动 + 词间停顿 + 可选打错回退)。
|
|
239
|
+
* 返回事件数组:
|
|
240
|
+
* { type: 'key', key, delayMs } —— 敲这个字符(delayMs 是敲之前的停顿)
|
|
241
|
+
* { type: 'wait', ms } —— 思考/走神停顿
|
|
242
|
+
* { type: 'typo', key, delayMs, fixMs } —— 敲错一个相邻键,然后退格(fixMs 后)
|
|
243
|
+
* { type: 'backspace', delayMs } —— 退格
|
|
244
|
+
* 长文本(超过 profile.pasteOverChars)由引擎走「粘贴」路径,不生成逐字符计划。
|
|
245
|
+
*/
|
|
246
|
+
export function typingPlan(text, rng, profile = HUMAN_PROFILES.fast) {
|
|
247
|
+
const source = String(text ?? '')
|
|
248
|
+
const events = []
|
|
249
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
250
|
+
const ch = source[i]
|
|
251
|
+
let delay = Math.round(gauss(rng, profile.typeMean, profile.typeSd))
|
|
252
|
+
delay = Math.round(clamp(delay, profile.typeMin, profile.typeMax))
|
|
253
|
+
if (ch === ' ') delay = Math.round(delay * 1.12)
|
|
254
|
+
if (SHIFT_HINTS.has(ch)) delay = Math.round(delay * 1.08)
|
|
255
|
+
if (rng() < (profile.typoRate || 0)) {
|
|
256
|
+
const wrong = typoKeyFor(ch, rng)
|
|
257
|
+
if (wrong && wrong !== ch) {
|
|
258
|
+
events.push({ type: 'typo', key: wrong, delayMs: delay, fixMs: Math.round(gauss(rng, 130, 40)) })
|
|
259
|
+
continue
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
events.push({ type: 'key', key: ch, delayMs: delay })
|
|
263
|
+
if (rng() < (profile.pauseChance || 0)) {
|
|
264
|
+
events.push({ type: 'wait', ms: randInt(rng, profile.pauseMs[0], profile.pauseMs[1]) })
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return events
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 邻键映射(QWERTY 手误只会在邻键上发生,随机字符反而不像人)。 */
|
|
271
|
+
const NEIGHBORS = {
|
|
272
|
+
a: 'sq', b: 'vn', c: 'xv', d: 'sf', e: 'wr', f: 'dg', g: 'fh', h: 'gj', i: 'uo', j: 'hk',
|
|
273
|
+
k: 'jl', l: 'k', m: 'n', n: 'bm', o: 'ip', p: 'o', q: 'wa', r: 'et', s: 'ad', t: 'ry',
|
|
274
|
+
u: 'yi', v: 'cb', w: 'qe', x: 'zc', y: 'tu', z: 'x',
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function typoKeyFor(ch, rng) {
|
|
278
|
+
const lower = String(ch || '').toLowerCase()
|
|
279
|
+
const ring = NEIGHBORS[lower]
|
|
280
|
+
if (!ring) return ''
|
|
281
|
+
return ring[Math.floor(rng() * ring.length)]
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* --------------------------------------------------------------------------
|
|
285
|
+
* 滚轮节奏
|
|
286
|
+
* ------------------------------------------------------------------------ */
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* 滚轮计划:一次滚轮 tick 只滚一小段,动量衰减(人不会一次 wheel 滚 600px)。
|
|
290
|
+
* 返回 [{ dy, delayMs }],dy 之和 = distance。
|
|
291
|
+
*/
|
|
292
|
+
export function scrollPlan(distance, rng, profile = HUMAN_PROFILES.fast) {
|
|
293
|
+
const total = Number(distance) || 0
|
|
294
|
+
const [minSteps, maxSteps] = profile?.scrollSteps || [2, 3]
|
|
295
|
+
const n = randInt(rng, minSteps, maxSteps)
|
|
296
|
+
const weights = Array.from({ length: n }, () => 0.6 + rng() * 0.8)
|
|
297
|
+
const sum = weights.reduce((a, b) => a + b, 0)
|
|
298
|
+
const [gapMin, gapMax] = profile?.scrollIntervalMs || [12, 40]
|
|
299
|
+
let acc = 0
|
|
300
|
+
return weights.map((w, i) => {
|
|
301
|
+
const dy = i === n - 1 ? Math.round(total - acc) : Math.round((total * w) / sum)
|
|
302
|
+
acc += dy
|
|
303
|
+
return { dy, delayMs: randInt(rng, gapMin, gapMax) }
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* --------------------------------------------------------------------------
|
|
308
|
+
* 反自动化指纹补丁(一次性 init script)
|
|
309
|
+
* ------------------------------------------------------------------------ */
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 生成注入脚本:收敛最常见的自动化静态指纹。
|
|
313
|
+
* 只改「明显不像真人浏览器」的部分,不做 Canvas/Audio 噪声(会破坏站点功能与
|
|
314
|
+
* 可复现性,副作用大于收益)。
|
|
315
|
+
*
|
|
316
|
+
* opts: { platform, languages, webglVendor, webglRenderer, hardwareConcurrency, deviceMemory }
|
|
317
|
+
*/
|
|
318
|
+
/**
|
|
319
|
+
* UA 客户端提示(UA-CH)的单一真源:JS 侧 navigator.userAgentData 与网络侧
|
|
320
|
+
* Sec-CH-UA / Sec-CH-UA-Full-Version-List 请求头必须用同一份品牌清单,否则
|
|
321
|
+
* 「JS 说 Google Chrome、请求头说 Chromium」这种口径不一致本身就是检测点。
|
|
322
|
+
* 引擎用它做 CDP Emulation.setUserAgentOverride 的 userAgentMetadata,
|
|
323
|
+
* stealthInitScript 用它做页内补丁——两边永远一致。
|
|
324
|
+
*/
|
|
325
|
+
export function uaClientHints(ua, uaFull, platform = 'Win32') {
|
|
326
|
+
const parts = /(?:Chrome|HeadlessChrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)/.exec(String(ua || ''))
|
|
327
|
+
const major = parts ? parts[1] : ''
|
|
328
|
+
const full = String(uaFull || '') || (parts ? `${parts[1]}.${parts[2]}.${parts[3]}.${parts[4]}` : '')
|
|
329
|
+
const os = /Mac/i.test(platform) ? 'macOS' : /Linux/i.test(platform) ? 'Linux' : 'Windows'
|
|
330
|
+
return {
|
|
331
|
+
brands: major ? [
|
|
332
|
+
{ brand: 'Chromium', version: major },
|
|
333
|
+
{ brand: 'Google Chrome', version: major },
|
|
334
|
+
{ brand: 'Not?A_Brand', version: '99' },
|
|
335
|
+
] : [],
|
|
336
|
+
fullVersionList: major ? [
|
|
337
|
+
{ brand: 'Chromium', version: full },
|
|
338
|
+
{ brand: 'Google Chrome', version: full },
|
|
339
|
+
{ brand: 'Not?A_Brand', version: '99.0.0.0' },
|
|
340
|
+
] : [],
|
|
341
|
+
platform: os,
|
|
342
|
+
platformVersion: os === 'Windows' ? '15.0.0' : '14.0.0',
|
|
343
|
+
architecture: 'x86',
|
|
344
|
+
bitness: '64',
|
|
345
|
+
model: '',
|
|
346
|
+
mobile: false,
|
|
347
|
+
wow64: false,
|
|
348
|
+
formFactors: ['Desktop'],
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function stealthInitScript(opts = {}) {
|
|
353
|
+
const platform = String(opts.platform || 'Win32')
|
|
354
|
+
const languages = Array.isArray(opts.languages) && opts.languages.length ? opts.languages : ['zh-CN', 'zh', 'en-US', 'en']
|
|
355
|
+
const webglVendor = String(opts.webglVendor || 'Google Inc. (Intel)')
|
|
356
|
+
const webglRenderer = String(opts.webglRenderer || 'ANGLE (Intel, Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0, D3D11)')
|
|
357
|
+
const cores = Number(opts.hardwareConcurrency) || 8
|
|
358
|
+
const memory = Number(opts.deviceMemory) || 8
|
|
359
|
+
/* UA:只在拿到「浏览器真实 UA」时才补丁。以前这里写了一个假版本号当兜底,
|
|
360
|
+
结果缓存里躺的是编造的版本号,而真实内核是 156.0.8078.4——版本对不上比
|
|
361
|
+
带着 Headless 更容易被服务端判定异常。现在没拿到真值就完全不改,交给启动参数。
|
|
362
|
+
注意:UA 字符串里的版本号被 Chrome 削减成 major.0.0.0 是正常行为(UA Reduction),
|
|
363
|
+
完整版本只出现在 UA-CH 的高熵字段里,所以完整版本由 opts.uaFull 单独传入。 */
|
|
364
|
+
const ua = String(opts.ua || '')
|
|
365
|
+
const uaParts = /(?:Chrome|HeadlessChrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)/.exec(ua)
|
|
366
|
+
const uaMajor = uaParts ? uaParts[1] : ''
|
|
367
|
+
const uaFull = String(opts.uaFull || '') || (uaParts ? `${uaParts[1]}.${uaParts[2]}.${uaParts[3]}.${uaParts[4]}` : '')
|
|
368
|
+
/* 屏幕口径:无头默认 screen=视口(1280×800 的「显示器」很假)。给常见桌面分辨率,
|
|
369
|
+
availHeight 扣掉任务栏。与 launch 的 screen 选项保持一致。 */
|
|
370
|
+
const screenW = Number(opts.screen && opts.screen.width) || 1920
|
|
371
|
+
const screenH = Number(opts.screen && opts.screen.height) || 1080
|
|
372
|
+
const hints = uaClientHints(ua, uaFull, platform)
|
|
373
|
+
const payload = {
|
|
374
|
+
platform,
|
|
375
|
+
languages,
|
|
376
|
+
webglVendor,
|
|
377
|
+
webglRenderer,
|
|
378
|
+
cores,
|
|
379
|
+
memory,
|
|
380
|
+
ua,
|
|
381
|
+
uaMajor,
|
|
382
|
+
uaFull,
|
|
383
|
+
screenW,
|
|
384
|
+
screenH,
|
|
385
|
+
availH: screenH - 40,
|
|
386
|
+
brands: hints.brands,
|
|
387
|
+
fullVersionList: hints.fullVersionList,
|
|
388
|
+
uaPlatform: hints.platform,
|
|
389
|
+
platformVersion: hints.platformVersion,
|
|
390
|
+
}
|
|
391
|
+
return `(() => {
|
|
392
|
+
const cfg = ${JSON.stringify(payload)};
|
|
393
|
+
const nativeToString = Function.prototype.toString;
|
|
394
|
+
const patched = new WeakMap();
|
|
395
|
+
const hidePatch = (fn, name) => {
|
|
396
|
+
try {
|
|
397
|
+
patched.set(fn, 'function ' + name + '() { [native code] }');
|
|
398
|
+
Object.defineProperty(fn, 'name', { value: name, configurable: true });
|
|
399
|
+
} catch (e) {}
|
|
400
|
+
return fn;
|
|
401
|
+
};
|
|
402
|
+
try {
|
|
403
|
+
Object.defineProperty(Function.prototype, 'toString', {
|
|
404
|
+
configurable: true,
|
|
405
|
+
writable: true,
|
|
406
|
+
value: hidePatch(function toString() {
|
|
407
|
+
if (patched.has(this)) return patched.get(this);
|
|
408
|
+
return nativeToString.call(this);
|
|
409
|
+
}, 'toString'),
|
|
410
|
+
});
|
|
411
|
+
} catch (e) {}
|
|
412
|
+
|
|
413
|
+
const defineGetter = (proto, prop, getter) => {
|
|
414
|
+
try {
|
|
415
|
+
Object.defineProperty(proto, prop, { configurable: true, get: hidePatch(getter, 'get ' + prop) });
|
|
416
|
+
} catch (e) {}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
try {
|
|
420
|
+
defineGetter(Navigator.prototype, 'webdriver', function webdriver() { return false; });
|
|
421
|
+
} catch (e) {}
|
|
422
|
+
|
|
423
|
+
/* UA:JS 侧与 HTTP 头必须一致(引擎在 launch 时也会带上同一个串)。
|
|
424
|
+
只有拿到真实 UA 才改写;否则保持浏览器自己的值,绝不编一个版本号。 */
|
|
425
|
+
try {
|
|
426
|
+
if (cfg.ua) defineGetter(Navigator.prototype, 'userAgent', function userAgent() { return cfg.ua; });
|
|
427
|
+
} catch (e) {}
|
|
428
|
+
|
|
429
|
+
/* UA-CH:HeadlessChrome 在 userAgentData.brands 里同样露馅。 */
|
|
430
|
+
try {
|
|
431
|
+
if (cfg.uaMajor) {
|
|
432
|
+
/* 品牌清单来自 uaClientHints(与网络头同一真源),不在这里另写一份。 */
|
|
433
|
+
const brands = cfg.brands;
|
|
434
|
+
const fullVersionList = cfg.fullVersionList;
|
|
435
|
+
/* 高熵取值在下方统一定义(要合并原生真值),这里只准备 brands / fullVersionList。 */
|
|
436
|
+
/* 新无头模式自带 userAgentData,且 brands 里带 HeadlessChrome——只补「没有」的情况
|
|
437
|
+
等于没补。这里无论有没有原生对象都覆盖:brands/fullVersionList 换成干净值,
|
|
438
|
+
其余高熵字段尽量保留原生真值(platformVersion 等原生报的才是对的)。 */
|
|
439
|
+
const nativeUAD = navigator.userAgentData;
|
|
440
|
+
const fillEntropy = (out, hints) => {
|
|
441
|
+
out.brands = brands;
|
|
442
|
+
out.mobile = false;
|
|
443
|
+
out.platform = cfg.uaPlatform;
|
|
444
|
+
for (const h of (hints || [])) {
|
|
445
|
+
if (h === 'platformVersion') out.platformVersion = out.platformVersion || cfg.platformVersion;
|
|
446
|
+
else if (h === 'architecture') out.architecture = out.architecture || 'x86';
|
|
447
|
+
else if (h === 'bitness') out.bitness = out.bitness || '64';
|
|
448
|
+
else if (h === 'model') out.model = out.model || '';
|
|
449
|
+
else if (h === 'uaFullVersion') out.uaFullVersion = cfg.uaFull;
|
|
450
|
+
else if (h === 'fullVersionList') out.fullVersionList = fullVersionList;
|
|
451
|
+
else if (h === 'wow64') out.wow64 = false;
|
|
452
|
+
else if (h === 'formFactors') out.formFactors = ['Desktop'];
|
|
453
|
+
}
|
|
454
|
+
return out;
|
|
455
|
+
};
|
|
456
|
+
const highEntropy = (hints) => {
|
|
457
|
+
if (nativeUAD && typeof nativeUAD.getHighEntropyValues === 'function') {
|
|
458
|
+
return nativeUAD.getHighEntropyValues(hints).then((v) => fillEntropy(v || {}, hints)).catch(() => fillEntropy({}, hints));
|
|
459
|
+
}
|
|
460
|
+
return Promise.resolve(fillEntropy({}, hints));
|
|
461
|
+
};
|
|
462
|
+
Object.defineProperty(Navigator.prototype, 'userAgentData', {
|
|
463
|
+
configurable: true,
|
|
464
|
+
get: hidePatch(function userAgentData() {
|
|
465
|
+
return {
|
|
466
|
+
brands,
|
|
467
|
+
mobile: false,
|
|
468
|
+
platform: cfg.uaPlatform,
|
|
469
|
+
getHighEntropyValues: hidePatch(highEntropy, 'getHighEntropyValues'),
|
|
470
|
+
toJSON: hidePatch(function toJSON() { return { brands, mobile: false, platform: cfg.uaPlatform } }, 'toJSON'),
|
|
471
|
+
};
|
|
472
|
+
}, 'get userAgentData'),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
} catch (e) {}
|
|
476
|
+
|
|
477
|
+
/* 通知权限:真人浏览器默认是 default,headless 里常被报成 denied。 */
|
|
478
|
+
try {
|
|
479
|
+
if (typeof Notification !== 'undefined') {
|
|
480
|
+
Object.defineProperty(Notification, 'permission', { configurable: true, get: hidePatch(function permission() { return 'default'; }, 'get permission') });
|
|
481
|
+
}
|
|
482
|
+
} catch (e) {}
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
if (!window.chrome) window.chrome = {};
|
|
486
|
+
if (!window.chrome.runtime) {
|
|
487
|
+
window.chrome.runtime = {
|
|
488
|
+
id: undefined,
|
|
489
|
+
connect: hidePatch(function connect() {}, 'connect'),
|
|
490
|
+
sendMessage: hidePatch(function sendMessage() {}, 'sendMessage'),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
if (!window.chrome.app) {
|
|
494
|
+
window.chrome.app = { isInstalled: false, InstallState: { DISABLED: 'disabled', INSTALLED: 'installed', NOT_INSTALLED: 'not_installed' }, RunningState: { CANNOT_RUN: 'cannot_run', READY_TO_RUN: 'ready_to_run', RUNNING: 'running' } };
|
|
495
|
+
}
|
|
496
|
+
/* 真 Chrome 有 csi()/loadTimes();headless 缺失会被指纹脚本记一笔。补上合理返回值。 */
|
|
497
|
+
if (!window.chrome.csi) {
|
|
498
|
+
window.chrome.csi = hidePatch(function csi() {
|
|
499
|
+
return { onloadT: Date.now(), startE: Date.now(), pageT: Math.round(performance.now()), tran: 15 };
|
|
500
|
+
}, 'csi');
|
|
501
|
+
}
|
|
502
|
+
if (!window.chrome.loadTimes) {
|
|
503
|
+
window.chrome.loadTimes = hidePatch(function loadTimes() {
|
|
504
|
+
const t = Date.now() / 1000;
|
|
505
|
+
return {
|
|
506
|
+
requestTime: t - 0.5, startLoadTime: t - 0.4, commitLoadTime: t - 0.3,
|
|
507
|
+
finishDocumentLoadTime: t - 0.2, finishLoadTime: t - 0.1, firstPaintTime: t - 0.15,
|
|
508
|
+
firstPaintAfterLoadTime: 0, navigationType: 'Other', wasFetchedViaSpdy: true,
|
|
509
|
+
wasNpnNegotiated: true, npnNegotiatedProtocol: 'h2', wasAlternateProtocolAvailable: false,
|
|
510
|
+
connectionInfo: 'h2',
|
|
511
|
+
};
|
|
512
|
+
}, 'loadTimes');
|
|
513
|
+
}
|
|
514
|
+
} catch (e) {}
|
|
515
|
+
|
|
516
|
+
try {
|
|
517
|
+
/* 真桌面 Chrome 报 5 个 PDF 插件、每个 length=1(application/pdf)。以前只给 3 个且
|
|
518
|
+
length=0,和真机对不上。mimeTypes 同样要有两条且 enabledPlugin 指回插件。 */
|
|
519
|
+
const pluginDefs = [
|
|
520
|
+
{ name: 'PDF Viewer', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
|
|
521
|
+
{ name: 'Chrome PDF Viewer', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
|
|
522
|
+
{ name: 'Chromium PDF Viewer', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
|
|
523
|
+
{ name: 'Microsoft Edge PDF Viewer', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
|
|
524
|
+
{ name: 'WebKit built-in PDF', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
|
|
525
|
+
];
|
|
526
|
+
/* 不用 Plugin 实例:其原型上的 name/filename/description 是只读 getter,
|
|
527
|
+
Object.assign 会抛 TypeError;普通对象足够骗过指纹探测。
|
|
528
|
+
列表只建一次:原生 navigator.plugins 每次返回同一对象,稳定身份更像真的。 */
|
|
529
|
+
const list = pluginDefs.map((p) => ({
|
|
530
|
+
name: p.name,
|
|
531
|
+
filename: p.filename,
|
|
532
|
+
description: p.description,
|
|
533
|
+
length: 1,
|
|
534
|
+
}));
|
|
535
|
+
for (const pl of list) {
|
|
536
|
+
const mime = { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: pl };
|
|
537
|
+
pl[0] = mime;
|
|
538
|
+
pl.item = hidePatch(function item(i) { return i === 0 ? mime : null; }, 'item');
|
|
539
|
+
pl.namedItem = hidePatch(function namedItem(n) { return n === 'application/pdf' ? mime : null; }, 'namedItem');
|
|
540
|
+
}
|
|
541
|
+
list.item = hidePatch(function item(i) { return list[i] || null; }, 'item');
|
|
542
|
+
list.namedItem = hidePatch(function namedItem(n) { return list.find((p) => p.name === n) || null; }, 'namedItem');
|
|
543
|
+
list.refresh = hidePatch(function refresh() { return undefined; }, 'refresh');
|
|
544
|
+
const mimes = [
|
|
545
|
+
{ type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: list[0] },
|
|
546
|
+
{ type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: list[0] },
|
|
547
|
+
];
|
|
548
|
+
mimes.item = hidePatch(function item(i) { return mimes[i] || null; }, 'item');
|
|
549
|
+
mimes.namedItem = hidePatch(function namedItem(n) { return mimes.find((m) => m.type === n) || null; }, 'namedItem');
|
|
550
|
+
const nativeDescriptor = Object.getOwnPropertyDescriptor(Navigator.prototype, 'plugins');
|
|
551
|
+
const nativeGet = nativeDescriptor && nativeDescriptor.get;
|
|
552
|
+
Object.defineProperty(Navigator.prototype, 'plugins', {
|
|
553
|
+
configurable: true,
|
|
554
|
+
get: hidePatch(function plugins() {
|
|
555
|
+
/* 任何异常都必须降级成原生值:getter 抛错会让页面自己的指纹脚本崩掉,比不伪装更可疑。 */
|
|
556
|
+
try { return list } catch (e) { return nativeGet ? nativeGet.call(this) : list }
|
|
557
|
+
}, 'get plugins'),
|
|
558
|
+
});
|
|
559
|
+
defineGetter(Navigator.prototype, 'mimeTypes', function mimeTypes() { return mimes; });
|
|
560
|
+
defineGetter(Navigator.prototype, 'pdfViewerEnabled', function pdfViewerEnabled() { return true; });
|
|
561
|
+
} catch (e) {}
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
defineGetter(Navigator.prototype, 'languages', function languages() { return cfg.languages.slice(); });
|
|
565
|
+
defineGetter(Navigator.prototype, 'platform', function platform() { return cfg.platform; });
|
|
566
|
+
defineGetter(Navigator.prototype, 'hardwareConcurrency', function hardwareConcurrency() { return cfg.cores; });
|
|
567
|
+
defineGetter(Navigator.prototype, 'deviceMemory', function deviceMemory() { return cfg.memory; });
|
|
568
|
+
} catch (e) {}
|
|
569
|
+
|
|
570
|
+
try {
|
|
571
|
+
const origQuery = navigator.permissions && navigator.permissions.query;
|
|
572
|
+
if (origQuery) {
|
|
573
|
+
navigator.permissions.query = hidePatch(function query(params) {
|
|
574
|
+
if (params && params.name === 'notifications') {
|
|
575
|
+
return Promise.resolve({ state: Notification.permission, onchange: null });
|
|
576
|
+
}
|
|
577
|
+
return origQuery.call(navigator.permissions, params);
|
|
578
|
+
}, 'query');
|
|
579
|
+
}
|
|
580
|
+
} catch (e) {}
|
|
581
|
+
|
|
582
|
+
try {
|
|
583
|
+
const patchGL = (proto) => {
|
|
584
|
+
if (!proto) return;
|
|
585
|
+
const orig = proto.getParameter;
|
|
586
|
+
proto.getParameter = hidePatch(function getParameter(param) {
|
|
587
|
+
if (param === 37445) return cfg.webglVendor; // UNMASKED_VENDOR_WEBGL
|
|
588
|
+
if (param === 37446) return cfg.webglRenderer; // UNMASKED_RENDERER_WEBGL
|
|
589
|
+
return orig.call(this, param);
|
|
590
|
+
}, 'getParameter');
|
|
591
|
+
};
|
|
592
|
+
patchGL(window.WebGLRenderingContext && WebGLRenderingContext.prototype);
|
|
593
|
+
patchGL(window.WebGL2RenderingContext && WebGL2RenderingContext.prototype);
|
|
594
|
+
} catch (e) {}
|
|
595
|
+
|
|
596
|
+
try {
|
|
597
|
+
if (!navigator.connection) {
|
|
598
|
+
Object.defineProperty(Navigator.prototype, 'connection', {
|
|
599
|
+
configurable: true,
|
|
600
|
+
get: hidePatch(function connection() { return { effectiveType: '4g', rtt: 50, downlink: 10, saveData: false }; }, 'get connection'),
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
} catch (e) {}
|
|
604
|
+
|
|
605
|
+
try {
|
|
606
|
+
/* 无头里 window.outerWidth/outerHeight 常是 0 或等于视口(真人窗口有边框/工具栏)。
|
|
607
|
+
outerHeight 必须 > innerHeight 才像真窗口;outerWidth 与视口同宽即可。 */
|
|
608
|
+
const w = window;
|
|
609
|
+
const fallbackW = (w.innerWidth && w.innerWidth > 0) ? w.innerWidth : 1280;
|
|
610
|
+
const fallbackH = (w.innerHeight && w.innerHeight > 0) ? w.innerHeight : 800;
|
|
611
|
+
if (!w.outerWidth) {
|
|
612
|
+
Object.defineProperty(w, 'outerWidth', { configurable: true, get: hidePatch(function outerWidth() { return fallbackW; }, 'get outerWidth') });
|
|
613
|
+
}
|
|
614
|
+
if (!w.outerHeight || w.outerHeight <= fallbackH) {
|
|
615
|
+
Object.defineProperty(w, 'outerHeight', { configurable: true, get: hidePatch(function outerHeight() { return fallbackH + 88; }, 'get outerHeight') });
|
|
616
|
+
}
|
|
617
|
+
/* 屏幕口径:无头默认 screen=视口,真桌面显示器恒 >= 窗口。与 launch 的 screen 选项一致。 */
|
|
618
|
+
if (typeof Screen !== 'undefined') {
|
|
619
|
+
defineGetter(Screen.prototype, 'width', function width() { return cfg.screenW; });
|
|
620
|
+
defineGetter(Screen.prototype, 'height', function height() { return cfg.screenH; });
|
|
621
|
+
defineGetter(Screen.prototype, 'availWidth', function availWidth() { return cfg.screenW; });
|
|
622
|
+
defineGetter(Screen.prototype, 'availHeight', function availHeight() { return cfg.availH; });
|
|
623
|
+
defineGetter(Screen.prototype, 'colorDepth', function colorDepth() { return 24; });
|
|
624
|
+
defineGetter(Screen.prototype, 'pixelDepth', function pixelDepth() { return 24; });
|
|
625
|
+
}
|
|
626
|
+
} catch (e) {}
|
|
627
|
+
})();`
|
|
628
|
+
}
|