@xbrowser/cli 1.21.0 → 1.22.0
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/README.md +1 -0
- package/dist/{browser-CNBSH53B.js → browser-BVRFSUXU.js} +3 -2
- package/dist/{browser-C2VEOJC2.js → browser-DSYUAE7H.js} +5 -4
- package/dist/{browser-VZOOFLAH.js → browser-Q67BJTI2.js} +4 -3
- package/dist/{cdp-driver-KFX4A6WR.js → cdp-driver-DC7EIUG5.js} +4 -3
- package/dist/{cdp-driver-7Z6ZAT5E.js → cdp-driver-T7D6H2RW.js} +335 -546
- package/dist/{cdp-driver-26LGCHXV.js → cdp-driver-WWO2UZDR.js} +3 -2
- package/dist/{chunk-Z5RTK4GW.js → chunk-2Q3GQRUP.js} +2 -2
- package/dist/{chunk-CLYZPSDR.js → chunk-4OU37CXP.js} +354 -576
- package/dist/{chunk-HWWG2ISJ.js → chunk-7OP2ISEY.js} +353 -575
- package/dist/{chunk-3FWLW7FS.js → chunk-A7NEA4PA.js} +39 -1
- package/dist/chunk-GYB5BOSP.js +602 -0
- package/dist/{chunk-ESJYANQO.js → chunk-IFKJO2UR.js} +360 -582
- package/dist/{chunk-NODRQGOK.js → chunk-IR6C24P7.js} +97 -0
- package/dist/{chunk-3KZ34AUC.js → chunk-MYH6FIBZ.js} +2 -1
- package/dist/{chunk-AVSTNODR.js → chunk-T4WTKBWI.js} +2 -2
- package/dist/{chunk-HBHOKZPN.js → chunk-V6KGBU5J.js} +97 -0
- package/dist/{chunk-IWVG4XYZ.js → chunk-VCVDILH6.js} +2 -1
- package/dist/cli.js +25 -13
- package/dist/daemon-main.js +20 -14
- package/dist/index.d.ts +37 -1
- package/dist/index.js +26 -15
- package/dist/keep-awake-M4KJS4B4.js +29 -0
- package/dist/{launcher-44STYRJC.js → launcher-IK2FKW6T.js} +1 -1
- package/dist/{launcher-EXJHHAUL.js → launcher-LUOMMGZC.js} +1 -1
- package/dist/{session-recorder-SLDBENVF.js → session-recorder-563ISSJK.js} +1 -1
- package/dist/{session-recorder-3BEVWHOK.js → session-recorder-GEZVQBKW.js} +1 -1
- package/dist/session-replayer-XM5L7LFD.js +927 -0
- package/dist/stealth-2AA2FSNN.js +29 -0
- package/dist/stealth-JOXGV34D.js +29 -0
- package/package.json +1 -1
- package/dist/session-replayer-EVD4HZBB.js +0 -413
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_STEALTH_CONFIG,
|
|
3
|
+
bezierTrajectory,
|
|
4
|
+
buildStealthInitScript,
|
|
5
|
+
landingOffset,
|
|
6
|
+
rand,
|
|
7
|
+
typingDelay
|
|
8
|
+
} from "./chunk-GYB5BOSP.js";
|
|
1
9
|
import {
|
|
2
10
|
connectToCDP,
|
|
3
11
|
launchChrome
|
|
4
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-MYH6FIBZ.js";
|
|
5
13
|
import {
|
|
6
14
|
errMsg
|
|
7
15
|
} from "./chunk-GDKLH7ZY.js";
|
|
@@ -14,6 +22,9 @@ import {
|
|
|
14
22
|
|
|
15
23
|
// src/cdp-driver/browser.ts
|
|
16
24
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
25
|
+
import { mkdirSync } from "fs";
|
|
26
|
+
import { join } from "path";
|
|
27
|
+
import { tmpdir } from "os";
|
|
17
28
|
|
|
18
29
|
// src/cdp-driver/context.ts
|
|
19
30
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
@@ -21,541 +32,6 @@ import { EventEmitter as EventEmitter2 } from "events";
|
|
|
21
32
|
// src/cdp-driver/page.ts
|
|
22
33
|
import { EventEmitter } from "events";
|
|
23
34
|
|
|
24
|
-
// src/cdp-driver/stealth.ts
|
|
25
|
-
var DEFAULT_STEALTH_CONFIG = {
|
|
26
|
-
// S191: macOS arm64 + Chrome 151 真实采样(来源:登录桥只读通道)
|
|
27
|
-
uaChProfile: {
|
|
28
|
-
brands: [
|
|
29
|
-
{ brand: "Not=A?Brand", version: "99" },
|
|
30
|
-
{ brand: "Google Chrome", version: "151" },
|
|
31
|
-
{ brand: "Chromium", version: "151" }
|
|
32
|
-
],
|
|
33
|
-
platform: "macOS",
|
|
34
|
-
platformVersion: "26.2.0",
|
|
35
|
-
architecture: "arm",
|
|
36
|
-
bitness: "64",
|
|
37
|
-
model: "",
|
|
38
|
-
uaFullVersion: "151.0.7922.175",
|
|
39
|
-
fullVersionList: [
|
|
40
|
-
{ brand: "Not=A?Brand", version: "99.0.0.0" },
|
|
41
|
-
{ brand: "Google Chrome", version: "151.0.7922.175" },
|
|
42
|
-
{ brand: "Chromium", version: "151.0.7922.175" }
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
bezierCurvature: [0.35, 0.6],
|
|
46
|
-
noiseAmplitude: 5.5,
|
|
47
|
-
overshootRange: [6, 14],
|
|
48
|
-
aimPause: [80, 280],
|
|
49
|
-
pressDuration: [60, 140],
|
|
50
|
-
releaseDrift: [0.8, 2.5],
|
|
51
|
-
landingOffsetSmall: [0.3, 2.5],
|
|
52
|
-
landingOffsetLarge: [1.5, 7],
|
|
53
|
-
smallElementThreshold: 30,
|
|
54
|
-
typingRhythm: {
|
|
55
|
-
fastProb: 0.22,
|
|
56
|
-
fastRange: [25, 60],
|
|
57
|
-
normalRange: [50, 350],
|
|
58
|
-
pauseProb: 0.18,
|
|
59
|
-
pauseRange: [400, 1200]
|
|
60
|
-
},
|
|
61
|
-
keyPressDuration: [50, 110],
|
|
62
|
-
typoProbability: 0.06,
|
|
63
|
-
wheelPeak: 180,
|
|
64
|
-
wheelDecayRate: 0.4
|
|
65
|
-
};
|
|
66
|
-
function rand(min, max) {
|
|
67
|
-
return min + Math.random() * (max - min);
|
|
68
|
-
}
|
|
69
|
-
function sleep(ms) {
|
|
70
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
71
|
-
}
|
|
72
|
-
function cosineEase(t) {
|
|
73
|
-
return 0.5 - 0.5 * Math.cos(Math.PI * t);
|
|
74
|
-
}
|
|
75
|
-
function bezierTrajectory(x0, y0, x1, y1, config = DEFAULT_STEALTH_CONFIG) {
|
|
76
|
-
const dist = Math.hypot(x1 - x0, y1 - y0);
|
|
77
|
-
const n = Math.max(10, Math.min(28, Math.round(dist / 15)));
|
|
78
|
-
const shortMove = dist < 120;
|
|
79
|
-
const curvature = shortMove ? rand(2, 6) : Math.max(dist * rand(...config.bezierCurvature), rand(18, 35));
|
|
80
|
-
const dir = Math.random() < 0.5 ? 1 : -1;
|
|
81
|
-
const d = dist || 1;
|
|
82
|
-
const dx = x1 - x0, dy = y1 - y0;
|
|
83
|
-
const c1x = x0 + dx * 0.3 - dy / d * curvature * 0.5 * dir;
|
|
84
|
-
const c1y = y0 + dy * 0.3 + dx / d * curvature * 0.5 * dir;
|
|
85
|
-
const c2x = x0 + dx * 0.7 - dy / d * curvature * 0.8 * dir;
|
|
86
|
-
const c2y = y0 + dy * 0.7 + dx / d * curvature * 0.8 * dir;
|
|
87
|
-
const points = [];
|
|
88
|
-
for (let i = 1; i <= n; i++) {
|
|
89
|
-
const t = cosineEase(i / n);
|
|
90
|
-
const mt = 1 - t;
|
|
91
|
-
let px = mt ** 3 * x0 + 3 * mt ** 2 * t * c1x + 3 * mt * t ** 2 * c2x + t ** 3 * x1;
|
|
92
|
-
let py = mt ** 3 * y0 + 3 * mt ** 2 * t * c1y + 3 * mt * t ** 2 * c2y + t ** 3 * y1;
|
|
93
|
-
const amp = shortMove ? Math.min(2, config.noiseAmplitude) : config.noiseAmplitude;
|
|
94
|
-
px += rand(-amp, amp);
|
|
95
|
-
py += rand(-amp, amp);
|
|
96
|
-
points.push({ x: px, y: py, delay: rand(9, 16) });
|
|
97
|
-
}
|
|
98
|
-
if (!shortMove) {
|
|
99
|
-
const over = rand(...config.overshootRange);
|
|
100
|
-
const ox = x1 + dx / d * over + rand(-2, 2);
|
|
101
|
-
const oy = y1 + dy / d * over + rand(-2, 2);
|
|
102
|
-
points.push({ x: ox, y: oy, delay: rand(14, 30) });
|
|
103
|
-
points.push({
|
|
104
|
-
x: x1 + dx / d * over * 0.4,
|
|
105
|
-
y: y1 + dy / d * over * 0.4,
|
|
106
|
-
delay: rand(14, 30)
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
points.push({ x: x1 + rand(-1, 1), y: y1 + rand(-1, 1), delay: rand(14, 30) });
|
|
110
|
-
return points;
|
|
111
|
-
}
|
|
112
|
-
function landingOffset(width, height, config = DEFAULT_STEALTH_CONFIG) {
|
|
113
|
-
const isSmall = Math.min(width, height) < config.smallElementThreshold;
|
|
114
|
-
const range = isSmall ? config.landingOffsetSmall : config.landingOffsetLarge;
|
|
115
|
-
const dx = rand(...range) * (Math.random() < 0.5 ? -1 : 1);
|
|
116
|
-
const dy = rand(...range) * (Math.random() < 0.5 ? -1 : 1);
|
|
117
|
-
return { dx, dy };
|
|
118
|
-
}
|
|
119
|
-
function typingDelay(config = DEFAULT_STEALTH_CONFIG) {
|
|
120
|
-
const roll = Math.random();
|
|
121
|
-
const r = config.typingRhythm;
|
|
122
|
-
if (roll < r.pauseProb) return rand(...r.pauseRange);
|
|
123
|
-
if (roll < r.pauseProb + r.fastProb) return rand(...r.fastRange);
|
|
124
|
-
return rand(...r.normalRange);
|
|
125
|
-
}
|
|
126
|
-
function wheelDelta(step, config = DEFAULT_STEALTH_CONFIG) {
|
|
127
|
-
return Math.round(
|
|
128
|
-
config.wheelPeak * Math.exp(-step * config.wheelDecayRate) * rand(0.85, 1.15)
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
var KEY_MAP = {};
|
|
132
|
-
for (let i = 97; i <= 122; i++) {
|
|
133
|
-
const ch = String.fromCharCode(i);
|
|
134
|
-
KEY_MAP[ch] = { key: ch, code: "Key" + ch.toUpperCase(), vk: i - 32 };
|
|
135
|
-
}
|
|
136
|
-
for (let i = 65; i <= 90; i++) {
|
|
137
|
-
const ch = String.fromCharCode(i);
|
|
138
|
-
KEY_MAP[ch] = { key: ch, code: "Key" + ch, vk: i, shift: true };
|
|
139
|
-
}
|
|
140
|
-
for (let i = 48; i <= 57; i++) {
|
|
141
|
-
const ch = String.fromCharCode(i);
|
|
142
|
-
KEY_MAP[ch] = { key: ch, code: "Digit" + ch, vk: i };
|
|
143
|
-
}
|
|
144
|
-
Object.assign(KEY_MAP, {
|
|
145
|
-
" ": { key: " ", code: "Space", vk: 32 },
|
|
146
|
-
".": { key: ".", code: "Period", vk: 190 },
|
|
147
|
-
"-": { key: "-", code: "Minus", vk: 189 },
|
|
148
|
-
"@": { key: "@", code: "Digit2", vk: 50, shift: true },
|
|
149
|
-
"_": { key: "_", code: "Minus", vk: 189, shift: true }
|
|
150
|
-
});
|
|
151
|
-
function buildStealthInitScript(config = DEFAULT_STEALTH_CONFIG) {
|
|
152
|
-
const prof = config.uaChProfile;
|
|
153
|
-
const profJson = prof ? JSON.stringify(prof) : "null";
|
|
154
|
-
return [
|
|
155
|
-
"(function(){",
|
|
156
|
-
' window.__xbStealthVer="57";',
|
|
157
|
-
" window.__xbUaChProf=" + profJson + ";",
|
|
158
|
-
// 1. AEL event proxy
|
|
159
|
-
" var o=EventTarget.prototype.addEventListener;",
|
|
160
|
-
" var fc=new InputDeviceCapabilities({firesTouchEvents:false});",
|
|
161
|
-
" var _ael=function(t,f){",
|
|
162
|
-
" var op=arguments[2];",
|
|
163
|
-
' if(typeof f!=="function")return o.call(this,t,f,op);',
|
|
164
|
-
" var w=function(e){",
|
|
165
|
-
" if(!e)return f.call(this,e);",
|
|
166
|
-
" return f.call(this,new Proxy(e,{get:function(k,p){",
|
|
167
|
-
' if(p==="sourceCapabilities")return fc;',
|
|
168
|
-
// S124 修正(d67 攻防):恒 true 是"过度伪装"——站点自己的合成事件
|
|
169
|
-
// 也变 true → 直接判定浏览器被篡改(比检测自动化更严重的指纹暴露)。
|
|
170
|
-
// 正确策略:透传原始值(CDP Input 事件本来就是 true,JS 合成本来是 false)
|
|
171
|
-
// + paste 定向伪装(合成的 paste 在真实场景都是 trusted 的键盘操作产物)
|
|
172
|
-
' if(p==="isTrusted"){',
|
|
173
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
174
|
-
" if(orig===true)return true;",
|
|
175
|
-
' if(k.type==="paste")return true;',
|
|
176
|
-
" return orig;",
|
|
177
|
-
" }",
|
|
178
|
-
' if((p==="clientX"||p==="clientY")&&k.type==="click"&&Number.isInteger(k[p])){',
|
|
179
|
-
" var _f=((k.timeStamp||Date.now())%89)/89*0.7+0.15;",
|
|
180
|
-
" return k[p]+_f;",
|
|
181
|
-
" }",
|
|
182
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
183
|
-
" }}));",
|
|
184
|
-
" };",
|
|
185
|
-
" return o.call(this,t,w,op);",
|
|
186
|
-
" };",
|
|
187
|
-
" EventTarget.prototype.addEventListener=_ael;",
|
|
188
|
-
// window.event isTrusted 伪装(S123):AEL 参数包装收不到 window.event
|
|
189
|
-
// (它是原始 Event 对象的隐式引用)。定义 getter 拦截读取。
|
|
190
|
-
" try{",
|
|
191
|
-
' var _weDesc=Object.getOwnPropertyDescriptor(Window.prototype,"event");',
|
|
192
|
-
" if(_weDesc&&_weDesc.get){",
|
|
193
|
-
" var _origWeGet=_weDesc.get;",
|
|
194
|
-
' Object.defineProperty(Window.prototype,"event",{',
|
|
195
|
-
" configurable:true,",
|
|
196
|
-
" get:function(){",
|
|
197
|
-
" var ev=_origWeGet.call(this);",
|
|
198
|
-
" if(!ev)return ev;",
|
|
199
|
-
" return new Proxy(ev,{get:function(k,p){",
|
|
200
|
-
' if(p==="isTrusted"){',
|
|
201
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
202
|
-
" if(orig===true)return true;",
|
|
203
|
-
' if(k.type==="paste")return true;',
|
|
204
|
-
" return orig;",
|
|
205
|
-
" }",
|
|
206
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
207
|
-
" }});",
|
|
208
|
-
" }",
|
|
209
|
-
" });",
|
|
210
|
-
" }",
|
|
211
|
-
" }catch(e){}",
|
|
212
|
-
// 2. Screen override (prototype-level, not instance-level)
|
|
213
|
-
" var _gw=function(){return 1728};",
|
|
214
|
-
" var _gh=function(){return 1117};",
|
|
215
|
-
" var _gah=function(){return 1092};",
|
|
216
|
-
' Object.defineProperty(Screen.prototype,"width",{get:_gw,configurable:true});',
|
|
217
|
-
' Object.defineProperty(Screen.prototype,"height",{get:_gh,configurable:true});',
|
|
218
|
-
' Object.defineProperty(Screen.prototype,"availWidth",{get:_gw,configurable:true});',
|
|
219
|
-
' Object.defineProperty(Screen.prototype,"availHeight",{get:_gah,configurable:true});',
|
|
220
|
-
// S174: UA Headless 标记清洗——headless launch 的 UA 含 HeadlessChrome/xxx
|
|
221
|
-
// (最高频检测面),同步清洗 userAgent/appVersion/userAgentData(brands+高熵值)。
|
|
222
|
-
// 原型+实例双层覆写(S172 模式)。
|
|
223
|
-
" try{",
|
|
224
|
-
' var fixUA=function(ua){return String(ua).replace("HeadlessChrome","Chrome");};',
|
|
225
|
-
' var fixBrands=function(list){return (list||[]).map(function(b){return (b.brand&&b.brand.indexOf("Headless")!==-1)?Object.assign({},b,{brand:b.brand.replace("HeadlessChrome","Chrome")}):b;});};',
|
|
226
|
-
' var _nuad=Object.getOwnPropertyDescriptor(Navigator.prototype,"userAgentData");',
|
|
227
|
-
" var wrapUAD=function(uad){",
|
|
228
|
-
" if(!uad||uad.__xbUA)return uad;",
|
|
229
|
-
" try{",
|
|
230
|
-
' Object.defineProperty(uad,"brands",{get:function(){return fixBrands(_nuad.get.call(navigator).brands);},configurable:true});',
|
|
231
|
-
" var _ghev=uad.getHighEntropyValues.bind(uad);",
|
|
232
|
-
" uad.getHighEntropyValues=function(hints){return _ghev(hints).then(function(v){",
|
|
233
|
-
' var o={};for(var k in v){o[k]=(typeof v[k]==="string")?fixUA(v[k]):(Array.isArray(v[k])?fixBrands(v[k]):v[k]);}',
|
|
234
|
-
" return o;});};",
|
|
235
|
-
" uad.__xbUA=true;",
|
|
236
|
-
" }catch(e){}",
|
|
237
|
-
" return uad;",
|
|
238
|
-
" };",
|
|
239
|
-
' var _nua=Object.getOwnPropertyDescriptor(Navigator.prototype,"userAgent");',
|
|
240
|
-
" if(_nua&&_nua.get){",
|
|
241
|
-
" var _nuag=function(){return fixUA(_nua.get.call(this));};",
|
|
242
|
-
' _nuag.toString=function(){return "function get userAgent() { [native code] }";};',
|
|
243
|
-
' Object.defineProperty(Navigator.prototype,"userAgent",{get:_nuag,configurable:true});',
|
|
244
|
-
" }",
|
|
245
|
-
' Object.defineProperty(navigator,"userAgent",{get:function(){return fixUA(_nua?_nua.get.call(this):"");},configurable:true});',
|
|
246
|
-
" if(_nuad&&_nuad.get){",
|
|
247
|
-
" var _nuadg=function(){return wrapUAD(_nuad.get.call(this));};",
|
|
248
|
-
' _nuadg.toString=function(){return "function get userAgentData() { [native code] }";};',
|
|
249
|
-
' Object.defineProperty(Navigator.prototype,"userAgentData",{get:_nuadg,configurable:true});',
|
|
250
|
-
" }",
|
|
251
|
-
// S190: userAgentData 垫片——headless Chrome 151 不暴露 UA-CH API,
|
|
252
|
-
// 缺失本身即 headless 指纹。从 UA 派生 brands/platform 垫片 + getHighEntropyValues。
|
|
253
|
-
" if(!navigator.userAgentData && window.__xbUaChProf){",
|
|
254
|
-
" var prof = window.__xbUaChProf;",
|
|
255
|
-
" var uad={",
|
|
256
|
-
' brands:prof.brands.map(function(b){return {brand:b.brand,version:b.version.split(".")[0]}}),',
|
|
257
|
-
" mobile:false,",
|
|
258
|
-
" platform:prof.platform,",
|
|
259
|
-
" getHighEntropyValues:function(hints){",
|
|
260
|
-
" return Promise.resolve().then(function(){",
|
|
261
|
-
" var all={brands:uad.brands,mobile:false,platform:prof.platform,",
|
|
262
|
-
" platformVersion:prof.platformVersion,architecture:prof.architecture,bitness:prof.bitness,model:prof.model,",
|
|
263
|
-
" uaFullVersion:prof.uaFullVersion,",
|
|
264
|
-
" fullVersionList:prof.fullVersionList};",
|
|
265
|
-
" var out={};",
|
|
266
|
-
" (hints||[]).forEach(function(h){if(h in all)out[h]=all[h]});",
|
|
267
|
-
" return out;",
|
|
268
|
-
" });",
|
|
269
|
-
" },",
|
|
270
|
-
" toJSON:function(){return{brands:uad.brands,mobile:false,platform:prof.platform}}",
|
|
271
|
-
" };",
|
|
272
|
-
' Object.defineProperty(navigator,"userAgentData",{get:function(){return uad},configurable:true});',
|
|
273
|
-
" }",
|
|
274
|
-
" }catch(e){}",
|
|
275
|
-
// hasFocus 与 visibilityState 联动(d29):恒 true 在 hidden 标签下暴露
|
|
276
|
-
// —— 真实浏览器失焦/后台时 hasFocus=false
|
|
277
|
-
// S172: 原型层覆写——实例赋值可被 Document.prototype.hasFocus.call(document) 逃逸
|
|
278
|
-
' Document.prototype.hasFocus=function(){return document.visibilityState==="visible";};',
|
|
279
|
-
// 4. Canvas/WebGL fingerprint: per-session stable noise (d20).
|
|
280
|
-
// Headless software raster differs subtly from Chrome GPU raster —
|
|
281
|
-
// toDataURL hashes fingerprint the rasterizer. Inject a stable
|
|
282
|
-
// (per-page-load) subpixel shift into fillText so hashes look like a
|
|
283
|
-
// distinct-but-consistent real GPU, and hide the HEADLESS tell in
|
|
284
|
-
// WebGL renderer strings.
|
|
285
|
-
" var _seed=Math.floor(Math.random()*2147483647);",
|
|
286
|
-
" var _prng=function(){_seed=(_seed*48271)%2147483647;return _seed/2147483647;};",
|
|
287
|
-
" var _dx=(_prng()*0.4-0.2).toFixed(3)*1, _dy=(_prng()*0.4-0.2).toFixed(3)*1;",
|
|
288
|
-
" var _fillText=CanvasRenderingContext2D.prototype.fillText;",
|
|
289
|
-
" CanvasRenderingContext2D.prototype.fillText=function(t,x,y,m){",
|
|
290
|
-
" return _fillText.call(this,t,x+_dx,y+_dy,m);",
|
|
291
|
-
" };",
|
|
292
|
-
" var _toDataURL=HTMLCanvasElement.prototype.toDataURL;",
|
|
293
|
-
" HTMLCanvasElement.prototype.toDataURL=function(){",
|
|
294
|
-
' var ctx=this.getContext("2d");',
|
|
295
|
-
" if(ctx){var d=ctx.getImageData(0,0,Math.min(this.width,2),Math.min(this.height,2));",
|
|
296
|
-
" for(var i=0;i<d.data.length;i+=4){if(d.data[i+3]>0){d.data[i]^=1;break;}}",
|
|
297
|
-
" ctx.putImageData(d,0,0);}",
|
|
298
|
-
" return _toDataURL.apply(this,arguments);",
|
|
299
|
-
" };",
|
|
300
|
-
" try{",
|
|
301
|
-
" var _gl=HTMLCanvasElement.prototype.getContext;",
|
|
302
|
-
" HTMLCanvasElement.prototype.getContext=function(t,o){",
|
|
303
|
-
" var c=_gl.call(this,t,o);",
|
|
304
|
-
' if(c&&(t==="webgl"||t==="experimental-webgl")&&c.getParameter){',
|
|
305
|
-
" var _gp=c.getParameter.bind(c);",
|
|
306
|
-
" c.getParameter=function(p){",
|
|
307
|
-
" var v=_gp(p);",
|
|
308
|
-
' if(typeof v==="string"&&/SwiftShader|Software|Rasterizer|Headless/i.test(v))',
|
|
309
|
-
' return "ANGLE (Apple, ANGLE Metal Renderer: Apple M2 Max, Unspecified Version)";',
|
|
310
|
-
" return v;};}",
|
|
311
|
-
" return c;};",
|
|
312
|
-
" }catch(e){}",
|
|
313
|
-
// 5. AudioContext fingerprint: per-load stable micro-noise on channel
|
|
314
|
-
// data (d21). DSP sum differences between headless software audio and
|
|
315
|
-
// real hardware audio are a classic fingerprint — add ±1e-7 level
|
|
316
|
-
// noise (inaudible, changes the sum hash).
|
|
317
|
-
" try{",
|
|
318
|
-
" var _gcd=AudioBuffer.prototype.getChannelData;",
|
|
319
|
-
" AudioBuffer.prototype.getChannelData=function(ch){",
|
|
320
|
-
" var d=_gcd.call(this,ch);",
|
|
321
|
-
' var key="__xb_audio_"+ch;',
|
|
322
|
-
" if(!this[key]){",
|
|
323
|
-
" this[key]=true;",
|
|
324
|
-
" for(var i=0;i<d.length;i+=997){d[i]=d[i]+(_prng()-0.5)*2e-7;}",
|
|
325
|
-
" }",
|
|
326
|
-
" return d;",
|
|
327
|
-
" };",
|
|
328
|
-
" var _gffd=AnalyserNode.prototype.getFloatFrequencyData;",
|
|
329
|
-
" AnalyserNode.prototype.getFloatFrequencyData=function(arr){",
|
|
330
|
-
" _gffd.call(this,arr);",
|
|
331
|
-
" for(var i=0;i<arr.length;i+=31){arr[i]=arr[i]+(_prng()-0.5)*0.01;}",
|
|
332
|
-
" };",
|
|
333
|
-
" var _gfbd=AnalyserNode.prototype.getByteFrequencyData;",
|
|
334
|
-
" AnalyserNode.prototype.getByteFrequencyData=function(arr){",
|
|
335
|
-
" _gfbd.call(this,arr);",
|
|
336
|
-
" for(var i=0;i<arr.length;i+=31){arr[i]=(arr[i]+((_prng()*3)|0))&255;}",
|
|
337
|
-
" };",
|
|
338
|
-
" }catch(e){}",
|
|
339
|
-
// 3b. Font metrics + speechSynthesis + battery (d22): headless tells
|
|
340
|
-
" try{",
|
|
341
|
-
' var _tmw=Object.getOwnPropertyDescriptor(TextMetrics.prototype,"width");',
|
|
342
|
-
" if(_tmw&&_tmw.get){",
|
|
343
|
-
" // S172: \u539F\u578B\u5C42\u8986\u5199\u2014\u2014\u5B9E\u4F8B(m)\u8986\u5199\u53EF\u88AB TextMetrics.prototype.width getter \u9003\u9038",
|
|
344
|
-
' Object.defineProperty(TextMetrics.prototype,"width",{get:function(){return _tmw.get.call(this)+_dx*0.01;},configurable:true});',
|
|
345
|
-
" }",
|
|
346
|
-
" }catch(e){}",
|
|
347
|
-
" try{",
|
|
348
|
-
' var _fakeVoices=["Alex","Daniel","Karen","Moira","Ralph","Samantha","Ting-Ting","Mei-Jia","Sinji","Yunda"];',
|
|
349
|
-
// S172: 原型层覆写——实例赋值可被 SpeechSynthesis.prototype.getVoices.call() 逃逸
|
|
350
|
-
" var _sv=SpeechSynthesis.prototype.getVoices;",
|
|
351
|
-
" SpeechSynthesis.prototype.getVoices=function(){",
|
|
352
|
-
" var real=_sv.call(this);",
|
|
353
|
-
" if(real&&real.length>50)return real;",
|
|
354
|
-
// 注意阈值从 0 改 50:iframe 原生约 10 个 —— 原阈值下 iframe 返回原生 10 个
|
|
355
|
-
// 而不是伪装 180(d33 暴露)。>50 = 主文档伪装列表已生效,其余返回伪装。
|
|
356
|
-
' return _fakeVoices.map(function(n,i){return {name:n,lang:i<2?"en-US":i<6?"en-GB":"zh-TW",localService:true,default:i===0,voiceURI:n};});',
|
|
357
|
-
" };",
|
|
358
|
-
// d33 修复:iframe 的 speechSynthesis 是独立实例(主文档 hook 不可达)——
|
|
359
|
-
// 轮询同源 iframe,对其 contentWindow 的原型同样 patch(S172: 原型层,防逃逸)
|
|
360
|
-
" try{",
|
|
361
|
-
" var _piv=function(){",
|
|
362
|
-
' var frs=document.querySelectorAll("iframe");',
|
|
363
|
-
" for(var i=0;i<frs.length;i++){try{",
|
|
364
|
-
" var cw=frs[i].contentWindow;",
|
|
365
|
-
" if(!cw||!cw.speechSynthesis||cw.speechSynthesis.__xbP)continue;",
|
|
366
|
-
" cw.speechSynthesis.__xbP=true;",
|
|
367
|
-
" var _sv2=cw.SpeechSynthesis.prototype.getVoices;",
|
|
368
|
-
" cw.SpeechSynthesis.prototype.getVoices=function(){var r=_sv2.call(this);if(r&&r.length>50)return r;",
|
|
369
|
-
' return _fakeVoices.map(function(n,j){return{name:n,lang:j<2?"en-US":j<6?"en-GB":"zh-TW",localService:true,default:j===0,voiceURI:n};});};',
|
|
370
|
-
" }catch(e2){}}",
|
|
371
|
-
" };",
|
|
372
|
-
" setInterval(_piv,2000);",
|
|
373
|
-
" var _mo=new MutationObserver(function(muts){",
|
|
374
|
-
" for(var k=0;k<muts.length;k++){var ns=muts[k].addedNodes;",
|
|
375
|
-
' for(var q=0;q<ns.length;q++){if(ns[q].tagName==="IFRAME")setTimeout(_piv,20);}}',
|
|
376
|
-
" });",
|
|
377
|
-
" _mo.observe(document.documentElement,{childList:true,subtree:true});",
|
|
378
|
-
" }catch(e){}",
|
|
379
|
-
" }catch(e){}",
|
|
380
|
-
" try{",
|
|
381
|
-
" var _gb=navigator.getBattery.bind(navigator);",
|
|
382
|
-
" navigator.getBattery=function(){",
|
|
383
|
-
" return _gb().then(function(b){",
|
|
384
|
-
' Object.defineProperty(b,"charging",{get:function(){return true;},configurable:true});',
|
|
385
|
-
" return b;});",
|
|
386
|
-
" };",
|
|
387
|
-
" }catch(e){}",
|
|
388
|
-
// 3c. WebRTC local IP leak guard (d23): headless STUN candidates can
|
|
389
|
-
// expose host IPs; mDNS-only candidates are the modern Chrome default.
|
|
390
|
-
" try{",
|
|
391
|
-
" var _oc=RTCPeerConnection.prototype.createOffer;",
|
|
392
|
-
" RTCPeerConnection.prototype.createOffer=function(){",
|
|
393
|
-
" var p=_oc.apply(this,arguments);",
|
|
394
|
-
" var self=this;",
|
|
395
|
-
" return p.then(function(offer){",
|
|
396
|
-
' offer.sdp=offer.sdp.split(String.fromCharCode(10)).filter(function(l){return l.indexOf("typ host")<0}).join(String.fromCharCode(10));',
|
|
397
|
-
" return offer;});",
|
|
398
|
-
" };",
|
|
399
|
-
" }catch(e){}",
|
|
400
|
-
// 3d-2. performance.now precision clamp (d34): full-precision timestamps
|
|
401
|
-
// (11 decimals) differ from site-isolation-clamped real Chrome (~100μs).
|
|
402
|
-
" try{",
|
|
403
|
-
" var _pn=Performance.prototype.now;",
|
|
404
|
-
" // S172: \u539F\u578B\u5C42\u8986\u5199\u2014\u2014\u5B9E\u4F8B\u8D4B\u503C\u53EF\u88AB Performance.prototype.now.call(performance) \u9003\u9038",
|
|
405
|
-
" Performance.prototype.now=function(){return Math.round(_pn.call(this)*10)/10;};",
|
|
406
|
-
' var _pto=Object.getOwnPropertyDescriptor(Performance.prototype,"timeOrigin");',
|
|
407
|
-
" if(_pto&&_pto.get){",
|
|
408
|
-
" // S173: timeOrigin \u771F\u4F2A\u88C5\u2014\u2014\u5360\u4F4D\u5C42\uFF08\u8FD4\u56DE\u771F\u503C\uFF09\u5347\u7EA7\u4E3A\u4F1A\u8BDD\u7EA7\u968F\u673A\u504F\u79FB\u3002",
|
|
409
|
-
" // \u9632 cross-page \u5BFC\u822A\u65F6\u523B\u5173\u8054\uFF1A\u4E0D\u540C\u7AD9\u70B9\u7528 timeOrigin \u7CBE\u786E\u5BF9\u9F50\u7528\u6237\u884C\u4E3A\u6863\u6848\u3002",
|
|
410
|
-
" // \u504F\u79FB\u7531\u672C\u9875 _seed \u6D3E\u751F\uFF08\u9875\u5185\u81EA\u6D3D\uFF0Cnow()+\u504F\u79FB\u4E00\u81F4\uFF09\uFF0C\u8DE8\u9875\u968F\u673A\uFF08\u4E0D\u53EF\u5173\u8054\uFF09\u3002",
|
|
411
|
-
" var _toff=Math.floor((_seed/2147483647)*600000-300000);",
|
|
412
|
-
" var _tog=function(){return _pto.get.call(performance)+_toff;};",
|
|
413
|
-
' _tog.toString=function(){return "function get timeOrigin() { [native code] }";};',
|
|
414
|
-
" // S172 \u5BA1\u8BA1\uFF1A\u5B9E\u4F8B\u8986\u5199\u53EF\u88AB\u539F\u578B getter \u9003\u9038\u2014\u2014\u539F\u578B\u5C42\u8986\u5199",
|
|
415
|
-
' Object.defineProperty(Performance.prototype,"timeOrigin",{get:_tog,configurable:true});',
|
|
416
|
-
' Object.defineProperty(performance,"timeOrigin",{get:_tog,configurable:true});',
|
|
417
|
-
" }",
|
|
418
|
-
" }catch(e){}",
|
|
419
|
-
// 3f. getCoalescedEvents 合成(d47):真实鼠标 125Hz 采样被浏览器按帧合并,
|
|
420
|
-
// 快速移动时 pointermove.getCoalescedEvents() 返回 2~6 个事件(群内
|
|
421
|
-
// ≈8ms);CDP Input 逐事件派发不走合并管线,coalesced>1 恒为 0(结构性
|
|
422
|
-
// 暴露,间隔模拟救不了——实测 Chrome 帧对齐时 CDP 连发事件被直接丢弃
|
|
423
|
-
// 而非合并)。按 125Hz 物理插值合成 coalesced 群:期望样本数 = dt/8ms-1,
|
|
424
|
-
// 合成事件用真 PointerEvent 构造 + 实例级 isTrusted/timeStamp 遮蔽。
|
|
425
|
-
" try{",
|
|
426
|
-
" if(window.PointerEvent&&PointerEvent.prototype.getCoalescedEvents){",
|
|
427
|
-
" var _gce=PointerEvent.prototype.getCoalescedEvents;",
|
|
428
|
-
" var _lm=null;",
|
|
429
|
-
" var _gceH=function(){",
|
|
430
|
-
" var list=_gce.call(this);",
|
|
431
|
-
' if(this.type!=="pointermove"||!this.isTrusted)return list;',
|
|
432
|
-
" var cur={x:this.clientX,y:this.clientY,ts:this.timeStamp};",
|
|
433
|
-
" var out=null;",
|
|
434
|
-
" if((!list||list.length<2)&&_lm){",
|
|
435
|
-
" var dt=cur.ts-_lm.ts,dx=cur.x-_lm.x,dy=cur.y-_lm.y;",
|
|
436
|
-
// dt 长(帧丢弃后)不代表群覆盖整个 dt —— 真实 coalesced 群只覆盖
|
|
437
|
-
// 最后一帧窗口(≤16.7ms,群内 ≈8ms=125Hz)。合成群从自身往回推 8ms
|
|
438
|
-
// 链,位移取末端占比(span/dt,dt 远大于 span 时位移趋零=丢弃后实况)。
|
|
439
|
-
" var expN=Math.floor(dt/8)-1;",
|
|
440
|
-
// dt<12ms(不足一帧+采样周期)时真实浏览器不会产生合并群 ——
|
|
441
|
-
// 单采样帧 coalesced=1,强行合成会出现 ~2ms 的超物理群内间隔。
|
|
442
|
-
" if(expN>0&&dt>=12&&Math.random()>0.15){",
|
|
443
|
-
" var n=Math.min(4,expN+(Math.random()<0.3?1:0));",
|
|
444
|
-
" var span=Math.min(dt,n*8.3);",
|
|
445
|
-
" var frac=Math.min(1,span/Math.max(dt,1));",
|
|
446
|
-
" out=[];",
|
|
447
|
-
" for(var i=1;i<=n;i++){",
|
|
448
|
-
// k=距自身的步数(含自身共 n+1 个事件,相邻恒 ≈8.3ms=125Hz 周期)
|
|
449
|
-
" var k=n+1-i;",
|
|
450
|
-
' var ev=new PointerEvent("pointermove",{',
|
|
451
|
-
' pointerId:this.pointerId,pointerType:"mouse",isPrimary:this.isPrimary,',
|
|
452
|
-
" clientX:cur.x-dx*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
453
|
-
" clientY:cur.y-dy*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
454
|
-
" screenX:this.screenX,screenY:this.screenY,",
|
|
455
|
-
" buttons:this.buttons,button:this.button,",
|
|
456
|
-
" bubbles:true,cancelable:true,composed:true,",
|
|
457
|
-
" width:this.width,height:this.height,pressure:this.pressure,",
|
|
458
|
-
" tiltX:this.tiltX,tiltY:this.tiltY,twist:this.twist});",
|
|
459
|
-
" var tsV=cur.ts-k*8.3-Math.random()*1.2;",
|
|
460
|
-
// isTrusted/timeStamp 是实例不可配置属性(defineProperty 抛
|
|
461
|
-
// "Cannot redefine"),改 Proxy 包装:getPrototypeOf/ownKeys 透传,
|
|
462
|
-
// instanceof 与属性枚举行为与真事件一致。IIFE 捕获本次循环的 tsV
|
|
463
|
-
// 快照 —— var 提升会让所有 Proxy 闭包共享最后一次赋值(实测四个
|
|
464
|
-
// 合成事件同时间戳、群内间隔塌到 ~2ms)。
|
|
465
|
-
" out.push((function(e2,t2){return new Proxy(e2,{get:function(t,p){",
|
|
466
|
-
' if(p==="isTrusted")return true;',
|
|
467
|
-
' if(p==="timeStamp")return t2;',
|
|
468
|
-
' var v=Reflect.get(t,p);return typeof v==="function"?v.bind(t):v;',
|
|
469
|
-
" }});})(ev,tsV));",
|
|
470
|
-
" }",
|
|
471
|
-
" out.push(this);",
|
|
472
|
-
" }",
|
|
473
|
-
" }",
|
|
474
|
-
" _lm=cur;",
|
|
475
|
-
" return out||list;",
|
|
476
|
-
" };",
|
|
477
|
-
" PointerEvent.prototype.getCoalescedEvents=_gceH;",
|
|
478
|
-
// name 反查伪装:var _gceH=fn 的具名推断会暴露 hook(原生 name 是
|
|
479
|
-
// "getCoalescedEvents")——toString 白名单管不到 name 属性。
|
|
480
|
-
' try{Object.defineProperty(_gceH,"name",{value:"getCoalescedEvents"});}catch(e){}',
|
|
481
|
-
" }",
|
|
482
|
-
" }catch(e){}",
|
|
483
|
-
// 3d. Chrome object depth (d24): automation fakes usually only set
|
|
484
|
-
// window.chrome = {}; deep checks hit app.run/runtime/csi/loadTimes.
|
|
485
|
-
" try{",
|
|
486
|
-
" if(window.chrome){",
|
|
487
|
-
' if(!window.chrome.app||!window.chrome.app.run)window.chrome.app={run:function(){},load:function(){},getDetails:function(){return null},InstallState:{DISABLED:"disabled",INSTALLED:"installed",NOT_INSTALLED:"not_installed"},RunningState:{CANNOT_RUN:"cannot_run",READY_TO_RUN:"ready_to_run",RUNNING:"running"}};',
|
|
488
|
-
' if(!window.chrome.runtime)window.chrome.runtime={OnInstalledReason:{CHROME_UPDATE:"chrome_update",INSTALL:"install",UPDATE:"update"},PlatformOs:{ANDROID:"android",CROS:"cros",LINUX:"linux",MAC:"mac",OPENBSD:"openbsd",WIN:"win"},connect:function(){},sendMessage:function(){},id:undefined};',
|
|
489
|
-
" if(!window.chrome.csi)window.chrome.csi=function(){return{};}",
|
|
490
|
-
" if(!window.chrome.loadTimes)window.chrome.loadTimes=function(){return{};}",
|
|
491
|
-
" }",
|
|
492
|
-
" }catch(e){}",
|
|
493
|
-
// 3e. Font availability patch (d25): headless Chromium misses some system
|
|
494
|
-
// fonts (e.g. Menlo on macOS) that real Chrome has. Register a FontFace
|
|
495
|
-
// aliasing the missing font to a local() equivalent so offsetWidth-based
|
|
496
|
-
// font probing sees the same availability as the faked environment.
|
|
497
|
-
" try{",
|
|
498
|
-
' var _fontAliases=[["Menlo","Courier New"],["SF Mono","Menlo"],["Segoe UI","Helvetica"]];',
|
|
499
|
-
" _fontAliases.forEach(function(pa){",
|
|
500
|
-
' try{var ff=new FontFace(pa[0],"local("+JSON.stringify(pa[1])+")");',
|
|
501
|
-
" document.fonts.add(ff);ff.load();}catch(e2){}",
|
|
502
|
-
" });",
|
|
503
|
-
" }catch(e){}",
|
|
504
|
-
// 3g. Notification.requestPermission 延迟(d62):headless 无原生横幅,
|
|
505
|
-
// request 瞬回 denied —— 真机 request 会 pending 在横幅上数秒到分钟。
|
|
506
|
-
// 延迟 2-6s 再 resolve,模拟横幅期(用户"看了下然后拒绝")。
|
|
507
|
-
" try{",
|
|
508
|
-
" if(window.Notification&&Notification.requestPermission){",
|
|
509
|
-
" var _nrp=Notification.requestPermission.bind(Notification);",
|
|
510
|
-
" Notification.requestPermission=function(cb){",
|
|
511
|
-
" return new Promise(function(res){",
|
|
512
|
-
" setTimeout(function(){_nrp().then(function(r){if(cb)try{cb(r)}catch(e){}res(r);});},2000+Math.random()*4000);",
|
|
513
|
-
" });",
|
|
514
|
-
" };",
|
|
515
|
-
" }",
|
|
516
|
-
" }catch(e){}",
|
|
517
|
-
// 3. toString disguise (name-list based)
|
|
518
|
-
" var _ts=Function.prototype.toString;",
|
|
519
|
-
" var _hf=document.hasFocus;",
|
|
520
|
-
" Function.prototype.toString=function(){",
|
|
521
|
-
' if(this===_ael)return"function addEventListener(type, callback) { [native code] }";',
|
|
522
|
-
' if(this===_hf)return"function hasFocus() { [native code] }";',
|
|
523
|
-
' if(this===_gw)return"function get width() { [native code] }";',
|
|
524
|
-
' if(this===_gh)return"function get height() { [native code] }";',
|
|
525
|
-
' if(this===_gah)return"function get availHeight() { [native code] }";',
|
|
526
|
-
' if(this===CanvasRenderingContext2D.prototype.fillText)return"function fillText() { [native code] }";',
|
|
527
|
-
' if(this===HTMLCanvasElement.prototype.toDataURL)return"function toDataURL() { [native code] }";',
|
|
528
|
-
' if(this===AnalyserNode.prototype.getFloatFrequencyData)return"function getFloatFrequencyData() { [native code] }";',
|
|
529
|
-
' if(this===AudioBuffer.prototype.getChannelData)return"function getChannelData() { [native code] }";',
|
|
530
|
-
' if(this===_gceH)return"function getCoalescedEvents() { [native code] }";',
|
|
531
|
-
' if(this===Document.prototype.hasFocus)return"function hasFocus() { [native code] }";',
|
|
532
|
-
' if(this===Performance.prototype.now)return"function now() { [native code] }";',
|
|
533
|
-
' if(this===SpeechSynthesis.prototype.getVoices)return"function getVoices() { [native code] }";',
|
|
534
|
-
" return _ts.call(this);",
|
|
535
|
-
" };",
|
|
536
|
-
// 4. onclick prototype hijack (dual-stream consistency)
|
|
537
|
-
" var _ba=function(k,p){",
|
|
538
|
-
' if(p==="isTrusted"){',
|
|
539
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
540
|
-
" if(orig===true)return true;",
|
|
541
|
-
' if(k.type==="paste")return true;',
|
|
542
|
-
" return orig;",
|
|
543
|
-
" }",
|
|
544
|
-
' if((p==="clientX"||p==="clientY")&&k.type==="click"&&Number.isInteger(k[p])&&k.isTrusted===true){',
|
|
545
|
-
" var _f=((k.timeStamp||Date.now())%89)/89*0.7+0.15;return k[p]+_f;",
|
|
546
|
-
" }",
|
|
547
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
548
|
-
" };",
|
|
549
|
-
' Object.defineProperty(Document.prototype,"onclick",{',
|
|
550
|
-
" configurable:true,",
|
|
551
|
-
" get:function(){var raw=this.__ocRaw||null;if(!raw)return null;var self=this;",
|
|
552
|
-
" return function(e){return raw.call(self,new Proxy(e,{get:function(k,p){return _ba(k,p)}}))}},",
|
|
553
|
-
" set:function(fn){this.__ocRaw=fn}",
|
|
554
|
-
" });",
|
|
555
|
-
"})()"
|
|
556
|
-
].join("\n");
|
|
557
|
-
}
|
|
558
|
-
|
|
559
35
|
// src/cdp-driver/mouse.ts
|
|
560
36
|
var XBMouseImpl = class {
|
|
561
37
|
conn;
|
|
@@ -596,26 +72,26 @@ var XBMouseImpl = class {
|
|
|
596
72
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: p.x, y: p.y, button: this._button });
|
|
597
73
|
this._x = p.x;
|
|
598
74
|
this._y = p.y;
|
|
599
|
-
await
|
|
75
|
+
await sleep(p.delay);
|
|
600
76
|
}
|
|
601
77
|
this._x = tx;
|
|
602
78
|
this._y = ty;
|
|
603
79
|
if (_truncated) {
|
|
604
80
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: tx, y: ty, button: this._button });
|
|
605
81
|
}
|
|
606
|
-
await
|
|
82
|
+
await sleep(rand(...DEFAULT_STEALTH_CONFIG.aimPause));
|
|
607
83
|
} else {
|
|
608
84
|
await this.move(tx, ty);
|
|
609
85
|
}
|
|
610
|
-
await this.down({ button });
|
|
611
|
-
await
|
|
86
|
+
await this.down({ button, clickCount: opts.clickCount ?? 1 });
|
|
87
|
+
await sleep(stealth ? rand(...DEFAULT_STEALTH_CONFIG.pressDuration) : opts.delay ?? 0);
|
|
612
88
|
const rx = stealth ? this._x + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._x;
|
|
613
89
|
const ry = stealth ? this._y + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._y;
|
|
614
90
|
this._x = rx;
|
|
615
91
|
this._y = ry;
|
|
616
92
|
await this.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: rx, y: ry, button, clickCount: opts.clickCount ?? 1 });
|
|
617
93
|
for (let i = 1; i < (opts.clickCount ?? 1); i++) {
|
|
618
|
-
if (opts.delay) await
|
|
94
|
+
if (opts.delay) await sleep(opts.delay);
|
|
619
95
|
await this.down({ button });
|
|
620
96
|
await this.up({ button });
|
|
621
97
|
}
|
|
@@ -631,7 +107,9 @@ var XBMouseImpl = class {
|
|
|
631
107
|
x: this._x,
|
|
632
108
|
y: this._y,
|
|
633
109
|
button,
|
|
634
|
-
|
|
110
|
+
// r23: press 必须与 release 声明同一 clickCount——Chrome 按序列计数
|
|
111
|
+
// 合成 click/dblclick,press 缺声明会把计数器重置(dblclick 永不合成)
|
|
112
|
+
clickCount: opts.clickCount ?? 1
|
|
635
113
|
});
|
|
636
114
|
}
|
|
637
115
|
async up(opts = {}) {
|
|
@@ -642,7 +120,7 @@ var XBMouseImpl = class {
|
|
|
642
120
|
x: this._x,
|
|
643
121
|
y: this._y,
|
|
644
122
|
button,
|
|
645
|
-
clickCount: 1
|
|
123
|
+
clickCount: opts.clickCount ?? 1
|
|
646
124
|
});
|
|
647
125
|
}
|
|
648
126
|
async move(x, y, opts = {}) {
|
|
@@ -653,7 +131,7 @@ var XBMouseImpl = class {
|
|
|
653
131
|
const dx = x - fromX;
|
|
654
132
|
const dy = y - fromY;
|
|
655
133
|
for (let i = 1; i <= steps; i++) {
|
|
656
|
-
if (stealth) await
|
|
134
|
+
if (stealth) await sleep(rand(16, 28));
|
|
657
135
|
const t = i / steps;
|
|
658
136
|
this._x = fromX + dx * t;
|
|
659
137
|
this._y = fromY + dy * t;
|
|
@@ -687,7 +165,7 @@ var XBMouseImpl = class {
|
|
|
687
165
|
const steps = opts.steps ?? Math.max(10, Math.min(24, Math.round(Math.hypot(x - this._x, y - this._y) / 20)));
|
|
688
166
|
const fx = this._x, fy = this._y;
|
|
689
167
|
for (let i = 1; i <= steps; i++) {
|
|
690
|
-
if (stealth) await
|
|
168
|
+
if (stealth) await sleep(rand(16, 28));
|
|
691
169
|
const t = i / steps;
|
|
692
170
|
this._x = fx + (x - fx) * t;
|
|
693
171
|
this._y = fy + (y - fy) * t;
|
|
@@ -700,7 +178,7 @@ var XBMouseImpl = class {
|
|
|
700
178
|
}
|
|
701
179
|
this._x = x;
|
|
702
180
|
this._y = y;
|
|
703
|
-
await
|
|
181
|
+
await sleep(rand(60, 140));
|
|
704
182
|
await this.send("Input.dispatchMouseEvent", {
|
|
705
183
|
type: "mouseReleased",
|
|
706
184
|
x,
|
|
@@ -723,7 +201,7 @@ var XBMouseImpl = class {
|
|
|
723
201
|
await this.conn.send(method, params, this.sessionId);
|
|
724
202
|
}
|
|
725
203
|
};
|
|
726
|
-
function
|
|
204
|
+
function sleep(ms) {
|
|
727
205
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
728
206
|
}
|
|
729
207
|
|
|
@@ -753,17 +231,17 @@ var XBKeyboardImpl = class {
|
|
|
753
231
|
await this.dispatchKeyEvent(downParams);
|
|
754
232
|
if (mapping.text) {
|
|
755
233
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
756
|
-
await
|
|
234
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
757
235
|
}
|
|
758
236
|
await this.dispatchKeyEvent({
|
|
759
237
|
type: "char",
|
|
760
238
|
text: mapping.text
|
|
761
239
|
});
|
|
762
240
|
}
|
|
763
|
-
if (delay > 0) await
|
|
241
|
+
if (delay > 0) await sleep2(delay);
|
|
764
242
|
else {
|
|
765
243
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
766
|
-
await
|
|
244
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
767
245
|
}
|
|
768
246
|
}
|
|
769
247
|
const upParams = {
|
|
@@ -809,16 +287,16 @@ var XBKeyboardImpl = class {
|
|
|
809
287
|
const fixedDelay = opts.delay ?? 0;
|
|
810
288
|
for (const char of text) {
|
|
811
289
|
if (fixedDelay > 0) {
|
|
812
|
-
await
|
|
290
|
+
await sleep2(fixedDelay);
|
|
813
291
|
} else if (stealth) {
|
|
814
|
-
await
|
|
292
|
+
await sleep2(typingDelay());
|
|
815
293
|
}
|
|
816
294
|
if (stealth && char.length === 1 && Math.random() < DEFAULT_STEALTH_CONFIG.typoProbability) {
|
|
817
295
|
const wrong = NEIGHBOR_KEYS[char];
|
|
818
296
|
if (wrong && wrong !== char) {
|
|
819
297
|
await this.dispatchKeySequence(resolveKeyMapping(wrong), stealth);
|
|
820
|
-
await
|
|
821
|
-
await this.dispatchKeySequence(
|
|
298
|
+
await sleep2(rand(120, 420));
|
|
299
|
+
await this.dispatchKeySequence(KEY_MAP.Backspace, stealth);
|
|
822
300
|
}
|
|
823
301
|
}
|
|
824
302
|
await this.dispatchKeySequence(resolveKeyMapping(char), stealth);
|
|
@@ -848,7 +326,7 @@ var XBKeyboardImpl = class {
|
|
|
848
326
|
await this.dispatchKeyEvent({ type: "char", text: mapping.text });
|
|
849
327
|
}
|
|
850
328
|
if (stealth) {
|
|
851
|
-
await
|
|
329
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
852
330
|
}
|
|
853
331
|
const upParams = {
|
|
854
332
|
type: "keyUp",
|
|
@@ -887,7 +365,7 @@ var XBKeyboardImpl = class {
|
|
|
887
365
|
}
|
|
888
366
|
await this.dispatchKeyEvent(downParams);
|
|
889
367
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
890
|
-
await
|
|
368
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
891
369
|
}
|
|
892
370
|
await this.dispatchKeyEvent({
|
|
893
371
|
type: "keyUp",
|
|
@@ -911,7 +389,7 @@ var XBKeyboardImpl = class {
|
|
|
911
389
|
await this.dispatchKeyEvent({ type: "rawKeyDown", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: bits });
|
|
912
390
|
await this.dispatchKeyEvent({ type: "keyDown", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
913
391
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
914
|
-
await
|
|
392
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
915
393
|
}
|
|
916
394
|
await this.dispatchKeyEvent({ type: "keyUp", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
917
395
|
await this.dispatchKeyEvent({ type: "keyUp", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: 0 });
|
|
@@ -921,7 +399,7 @@ var XBKeyboardImpl = class {
|
|
|
921
399
|
}
|
|
922
400
|
};
|
|
923
401
|
function resolveKeyMapping(key) {
|
|
924
|
-
if (
|
|
402
|
+
if (KEY_MAP[key]) return KEY_MAP[key];
|
|
925
403
|
if (key.length === 1) {
|
|
926
404
|
const lower = key.toLowerCase();
|
|
927
405
|
if (lower >= "a" && lower <= "z") {
|
|
@@ -938,7 +416,7 @@ function resolveKeyMapping(key) {
|
|
|
938
416
|
}
|
|
939
417
|
return { key, code: key };
|
|
940
418
|
}
|
|
941
|
-
var
|
|
419
|
+
var KEY_MAP = {
|
|
942
420
|
Enter: { key: "Enter", code: "Enter", text: "\r", keyCode: 13 },
|
|
943
421
|
Tab: { key: "Tab", code: "Tab", text: " ", keyCode: 9 },
|
|
944
422
|
Escape: { key: "Escape", code: "Escape", keyCode: 27 },
|
|
@@ -1007,7 +485,7 @@ var NEIGHBOR_KEYS = {
|
|
|
1007
485
|
"8": "9",
|
|
1008
486
|
"9": "0"
|
|
1009
487
|
};
|
|
1010
|
-
function
|
|
488
|
+
function sleep2(ms) {
|
|
1011
489
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1012
490
|
}
|
|
1013
491
|
|
|
@@ -1299,6 +777,14 @@ var XBLocatorImpl = class _XBLocatorImpl {
|
|
|
1299
777
|
await waitForActionable(this.page, this.selector, opts);
|
|
1300
778
|
await scrollIntoView(this.page, this.selector);
|
|
1301
779
|
await this.click({ ...opts });
|
|
780
|
+
await this.page.evaluate(`
|
|
781
|
+
(function() {
|
|
782
|
+
const el = ${this._q(this.selector)};
|
|
783
|
+
if (!el) return;
|
|
784
|
+
if (document.activeElement !== el) el.focus();
|
|
785
|
+
if ((el.value || el.textContent || '') !== '') document.execCommand('selectAll');
|
|
786
|
+
})()
|
|
787
|
+
`);
|
|
1302
788
|
if (process.env.XBROWSER_STEALTH !== "off" && value.length >= 40 && process.env.XBROWSER_FILL_TYPE !== "type") {
|
|
1303
789
|
try {
|
|
1304
790
|
const { pasteViaClipboard, syntheticPaste } = await import("./clipboard-BOL2GP2E.js");
|
|
@@ -2054,6 +1540,189 @@ var XBPageImpl = class _XBPageImpl {
|
|
|
2054
1540
|
await this.conn.send("Network.enable", void 0, this.sessionId);
|
|
2055
1541
|
await this.conn.send("DOM.enable", void 0, this.sessionId).catch(() => {
|
|
2056
1542
|
});
|
|
1543
|
+
if (this._contextImpl.ignoreHTTPSErrors) {
|
|
1544
|
+
await this.conn.send("Security.enable", void 0, this.sessionId).catch(() => {
|
|
1545
|
+
});
|
|
1546
|
+
await this.conn.send("Security.setIgnoreCertificateErrors", { ignore: true }, this.sessionId).catch(() => {
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
if (this._contextImpl.httpCredentials) {
|
|
1550
|
+
await this.conn.send("Fetch.enable", {
|
|
1551
|
+
patterns: [{ urlPattern: "*", requestStage: "Request" }],
|
|
1552
|
+
handleAuthRequests: true
|
|
1553
|
+
}, this.sessionId).catch(() => {
|
|
1554
|
+
});
|
|
1555
|
+
this._subscriptions.push(
|
|
1556
|
+
this.conn.subscribe("Fetch.requestPaused", this.sessionId, (params) => {
|
|
1557
|
+
if (this._interceptionEnabled) return;
|
|
1558
|
+
const p = params;
|
|
1559
|
+
this.conn.send("Fetch.continueRequest", { requestId: p.requestId }, this.sessionId).catch(() => {
|
|
1560
|
+
});
|
|
1561
|
+
})
|
|
1562
|
+
);
|
|
1563
|
+
this._subscriptions.push(
|
|
1564
|
+
this.conn.subscribe("Fetch.authRequired", this.sessionId, (params) => {
|
|
1565
|
+
const p = params;
|
|
1566
|
+
const creds = this._contextImpl.httpCredentials;
|
|
1567
|
+
this.conn.send("Fetch.continueWithAuth", {
|
|
1568
|
+
requestId: p.requestId,
|
|
1569
|
+
authChallengeResponse: creds ? { response: "ProvideCredentials", username: creds.username, password: creds.password } : { response: "CancelAuth" }
|
|
1570
|
+
}, this.sessionId).catch(() => {
|
|
1571
|
+
});
|
|
1572
|
+
})
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
await this.conn.send("Page.addScriptToEvaluateOnNewDocument", {
|
|
1576
|
+
source: [
|
|
1577
|
+
"try { window.print = function() {}; window.__xb_print_suppressed = true; } catch (e) {}",
|
|
1578
|
+
"try {",
|
|
1579
|
+
" if (window.showOpenFilePicker) {",
|
|
1580
|
+
" var __xb_mkHandle = function(name, content) {",
|
|
1581
|
+
' var file = new File([content], name, { type: "text/plain" });',
|
|
1582
|
+
" return {",
|
|
1583
|
+
' kind: "file", name: name,',
|
|
1584
|
+
" getFile: function() { return Promise.resolve(file); },",
|
|
1585
|
+
" createWritable: function() { return Promise.resolve({ write: function() { return Promise.resolve(); }, close: function() { return Promise.resolve(); } }); },",
|
|
1586
|
+
" isSameEntry: function() { return Promise.resolve(false); },",
|
|
1587
|
+
' queryPermission: function() { return Promise.resolve("granted"); },',
|
|
1588
|
+
' requestPermission: function() { return Promise.resolve("granted"); },',
|
|
1589
|
+
" };",
|
|
1590
|
+
" };",
|
|
1591
|
+
" window.showOpenFilePicker = function() {",
|
|
1592
|
+
' return Promise.resolve([__xb_mkHandle("xbrowser-stub.txt", "xbrowser fs access stub")]);',
|
|
1593
|
+
" };",
|
|
1594
|
+
" window.showSaveFilePicker = function() {",
|
|
1595
|
+
' return Promise.resolve(__xb_mkHandle("xbrowser-stub-save.txt", ""));',
|
|
1596
|
+
" };",
|
|
1597
|
+
" window.showDirectoryPicker = function() {",
|
|
1598
|
+
" var emptyIter = function() { return [][Symbol.iterator](); };",
|
|
1599
|
+
" return Promise.resolve({",
|
|
1600
|
+
' kind: "directory", name: "xbrowser-stub-dir",',
|
|
1601
|
+
" values: emptyIter, entries: emptyIter, keys: emptyIter,",
|
|
1602
|
+
' getDirectoryHandle: function() { return Promise.reject(new Error("stub empty dir")); },',
|
|
1603
|
+
' getFileHandle: function() { return Promise.reject(new Error("stub empty dir")); },',
|
|
1604
|
+
" isSameEntry: function() { return Promise.resolve(false); },",
|
|
1605
|
+
' queryPermission: function() { return Promise.resolve("granted"); },',
|
|
1606
|
+
' requestPermission: function() { return Promise.resolve("granted"); },',
|
|
1607
|
+
" });",
|
|
1608
|
+
" };",
|
|
1609
|
+
" window.__xb_fs_stub_installed = true;",
|
|
1610
|
+
" }",
|
|
1611
|
+
"} catch (e) {}",
|
|
1612
|
+
// sup-s7: 右键菜单压制——headful 下 CDP 右键弹浏览器原生菜单(CDP
|
|
1613
|
+
// 无法关闭浏览器 UI)。document 捕获阶段 preventDefault 抑制原生
|
|
1614
|
+
// 菜单;不阻断传播,录制 contextmenu 事件与页面自定义菜单不受影响。
|
|
1615
|
+
"try {",
|
|
1616
|
+
' document.addEventListener("contextmenu", function(e) { e.preventDefault(); }, true);',
|
|
1617
|
+
" window.__xb_ctxmenu_suppressed = true;",
|
|
1618
|
+
"} catch (e) {}",
|
|
1619
|
+
// sup-s10: Notification 守卫——new Notification() 弹 OS 级系统横幅
|
|
1620
|
+
// (headful 污染屏幕,等待通知交互的流程挂起)。no-op 包装但保
|
|
1621
|
+
// API 形状:permission/granted、requestPermission→granted、实例
|
|
1622
|
+
// title/close 可用——页面通知流程无感继续。
|
|
1623
|
+
"try {",
|
|
1624
|
+
" var XBN = function Notification(title, options) {",
|
|
1625
|
+
" this.title = title;",
|
|
1626
|
+
' this.body = (options && options.body) || "";',
|
|
1627
|
+
' this.tag = (options && options.tag) || "";',
|
|
1628
|
+
" this.onclick = null; this.onshow = null; this.onerror = null; this.onclose = null;",
|
|
1629
|
+
" };",
|
|
1630
|
+
" XBN.prototype.close = function() {};",
|
|
1631
|
+
' XBN.permission = "granted";',
|
|
1632
|
+
' XBN.requestPermission = function() { return Promise.resolve("granted"); };',
|
|
1633
|
+
" XBN.maxActions = (window.Notification && window.Notification.maxActions) || 2;",
|
|
1634
|
+
" window.Notification = XBN;",
|
|
1635
|
+
" window.__xb_notification_suppressed = true;",
|
|
1636
|
+
"} catch (e) {}",
|
|
1637
|
+
// sup-W1: WebAPI 选择器/配对框家族 stub(1/7 Serial)——
|
|
1638
|
+
// navigator.serial.requestPort() 弹浏览器原生串口选择器(CDP 无法
|
|
1639
|
+
// 拦截),headless 下 promise 挂起。stub 返回 rejected Promise
|
|
1640
|
+
// (NotFoundError),页面 catch 分支接管、流程继续。
|
|
1641
|
+
"try {",
|
|
1642
|
+
" if (navigator.serial) {",
|
|
1643
|
+
" navigator.serial.requestPort = function() {",
|
|
1644
|
+
' return Promise.reject(new DOMException("xbrowser serial stub", "NotFoundError"));',
|
|
1645
|
+
" };",
|
|
1646
|
+
" window.__xb_serial_stubbed = true;",
|
|
1647
|
+
" }",
|
|
1648
|
+
"} catch (e) {}",
|
|
1649
|
+
// sup-W2: WebAPI stub(2/7 USB)——requestDevice 弹原生设备配对框,
|
|
1650
|
+
// 同 Serial pattern:rejected Promise(NotFoundError),catch 接管。
|
|
1651
|
+
"try {",
|
|
1652
|
+
" if (navigator.usb) {",
|
|
1653
|
+
" navigator.usb.requestDevice = function() {",
|
|
1654
|
+
' return Promise.reject(new DOMException("xbrowser usb stub", "NotFoundError"));',
|
|
1655
|
+
" };",
|
|
1656
|
+
" window.__xb_usb_stubbed = true;",
|
|
1657
|
+
" }",
|
|
1658
|
+
"} catch (e) {}",
|
|
1659
|
+
// sup-W3: WebAPI stub(3/7 Bluetooth)——requestDevice 弹原生蓝牙
|
|
1660
|
+
// 配对框,同 Serial/USB pattern:rejected Promise(NotFoundError)。
|
|
1661
|
+
// CI linux headless 下 navigator.bluetooth 原生不存在——缺失时合成
|
|
1662
|
+
// 对象再包装,保证跨平台语义一致(requestDevice 恒 rejected)。
|
|
1663
|
+
"try {",
|
|
1664
|
+
" if (!navigator.bluetooth) {",
|
|
1665
|
+
' try { Object.defineProperty(navigator, "bluetooth", { value: {}, configurable: true }); } catch (e) {}',
|
|
1666
|
+
" }",
|
|
1667
|
+
" if (navigator.bluetooth) {",
|
|
1668
|
+
" navigator.bluetooth.requestDevice = function() {",
|
|
1669
|
+
' return Promise.reject(new DOMException("xbrowser ble stub", "NotFoundError"));',
|
|
1670
|
+
" };",
|
|
1671
|
+
" window.__xb_ble_stubbed = true;",
|
|
1672
|
+
" }",
|
|
1673
|
+
"} catch (e) {}",
|
|
1674
|
+
// sup-W4: WebAPI stub(4/7 HID)——requestDevices 弹原生 HID 设备
|
|
1675
|
+
// 选择器,同家族 pattern:rejected Promise(NotFoundError)。
|
|
1676
|
+
"try {",
|
|
1677
|
+
" if (navigator.hid) {",
|
|
1678
|
+
" navigator.hid.requestDevices = function() {",
|
|
1679
|
+
' return Promise.reject(new DOMException("xbrowser hid stub", "NotFoundError"));',
|
|
1680
|
+
" };",
|
|
1681
|
+
" window.__xb_hid_stubbed = true;",
|
|
1682
|
+
" }",
|
|
1683
|
+
"} catch (e) {}",
|
|
1684
|
+
// sup-W5: WebAPI stub(5/7 WakeLock)——request('screen') 在无用户
|
|
1685
|
+
// 激活/权限时挂起或拒绝,等待 wake 事件的流程死锁。stub 返回合成
|
|
1686
|
+
// sentinel(release 可用,不真实持锁)。
|
|
1687
|
+
"try {",
|
|
1688
|
+
" if (navigator.wakeLock) {",
|
|
1689
|
+
" navigator.wakeLock.request = function() {",
|
|
1690
|
+
" return Promise.resolve({",
|
|
1691
|
+
" released: false,",
|
|
1692
|
+
' type: "screen",',
|
|
1693
|
+
" release: function() { this.released = true; return Promise.resolve(); },",
|
|
1694
|
+
" addEventListener: function() {},",
|
|
1695
|
+
" removeEventListener: function() {},",
|
|
1696
|
+
" });",
|
|
1697
|
+
" };",
|
|
1698
|
+
" window.__xb_wakelock_stubbed = true;",
|
|
1699
|
+
" }",
|
|
1700
|
+
"} catch (e) {}",
|
|
1701
|
+
// sup-W6: WebAPI stub(6/7 IdleDetector)——start() 需权限气泡授权
|
|
1702
|
+
// 才能继续,headless 下挂起。stub 返回 rejected(NotAllowedError),
|
|
1703
|
+
// 页面 catch 分支接管。
|
|
1704
|
+
"try {",
|
|
1705
|
+
" if (window.IdleDetector) {",
|
|
1706
|
+
" IdleDetector.start = function() {",
|
|
1707
|
+
' return Promise.reject(new DOMException("xbrowser idle stub", "NotAllowedError"));',
|
|
1708
|
+
" };",
|
|
1709
|
+
" window.__xb_idle_stubbed = true;",
|
|
1710
|
+
" }",
|
|
1711
|
+
"} catch (e) {}",
|
|
1712
|
+
// sup-W7: WebAPI stub(7/7 PaymentRequest)——show() 弹浏览器支付
|
|
1713
|
+
// 面板(无用户交互不关闭),headless 下 promise 挂起。stub 返回
|
|
1714
|
+
// rejected(NotAllowedError),页面 catch 分支接管。
|
|
1715
|
+
"try {",
|
|
1716
|
+
" if (window.PaymentRequest) {",
|
|
1717
|
+
" PaymentRequest.prototype.show = function() {",
|
|
1718
|
+
' return Promise.reject(new DOMException("xbrowser pay stub", "NotAllowedError"));',
|
|
1719
|
+
" };",
|
|
1720
|
+
" window.__xb_pay_stubbed = true;",
|
|
1721
|
+
" }",
|
|
1722
|
+
"} catch (e) {}"
|
|
1723
|
+
].join("\n")
|
|
1724
|
+
}, this.sessionId).catch(() => {
|
|
1725
|
+
});
|
|
2057
1726
|
this.setupPageEvents();
|
|
2058
1727
|
this.setupNetworkEvents();
|
|
2059
1728
|
this.setupConsoleEvents();
|
|
@@ -2494,7 +2163,9 @@ Last error: ${lastError.message}` : "";
|
|
|
2494
2163
|
await this.locator(selector).click(opts);
|
|
2495
2164
|
}
|
|
2496
2165
|
async dblclick(selector, opts = {}) {
|
|
2497
|
-
|
|
2166
|
+
const locator = this.locator(selector);
|
|
2167
|
+
await locator.click({ ...opts, clickCount: 1 });
|
|
2168
|
+
await locator.click({ ...opts, clickCount: 2 });
|
|
2498
2169
|
}
|
|
2499
2170
|
async fill(selector, value, opts = {}) {
|
|
2500
2171
|
await this.locator(selector).fill(value, opts);
|
|
@@ -2611,6 +2282,26 @@ Last error: ${lastError.message}` : "";
|
|
|
2611
2282
|
);
|
|
2612
2283
|
this._viewportSize = size;
|
|
2613
2284
|
}
|
|
2285
|
+
/**
|
|
2286
|
+
* env-E2: 缩放变异——deviceScaleFactor 切换(CSS 像素坐标空间不变,
|
|
2287
|
+
* 物理像素翻倍)。保留当前 CSS 视口尺寸,只换 DSF。
|
|
2288
|
+
*/
|
|
2289
|
+
async setDeviceScaleFactor(dsf) {
|
|
2290
|
+
const size = this._viewportSize ?? await this.evaluate(
|
|
2291
|
+
"({ width: window.innerWidth, height: window.innerHeight })"
|
|
2292
|
+
);
|
|
2293
|
+
await this.conn.send(
|
|
2294
|
+
"Emulation.setDeviceMetricsOverride",
|
|
2295
|
+
{
|
|
2296
|
+
width: size.width,
|
|
2297
|
+
height: size.height,
|
|
2298
|
+
deviceScaleFactor: dsf,
|
|
2299
|
+
mobile: false
|
|
2300
|
+
},
|
|
2301
|
+
this.sessionId
|
|
2302
|
+
);
|
|
2303
|
+
this._viewportSize = size;
|
|
2304
|
+
}
|
|
2614
2305
|
// ── Scripts ─────────────────────────────────────────────────
|
|
2615
2306
|
async addInitScript(script) {
|
|
2616
2307
|
await this.conn.send(
|
|
@@ -2834,6 +2525,12 @@ Last error: ${lastError.message}` : "";
|
|
|
2834
2525
|
async _cdpSend(method, params) {
|
|
2835
2526
|
return this.conn.send(method, params, this.sessionId);
|
|
2836
2527
|
}
|
|
2528
|
+
/** sup-s11: beforeunload 自动应答语义——'accept'(默认,离开页面,与录制
|
|
2529
|
+
* 意图一致)或 'dismiss'(取消导航留守原页,尽力而为:此构建上 CDP
|
|
2530
|
+
* accept:false 对浏览器侧导航的取消语义不稳定,不保证)。 */
|
|
2531
|
+
setBeforeUnloadBehavior(mode) {
|
|
2532
|
+
this._beforeUnloadAccept = mode === "accept";
|
|
2533
|
+
}
|
|
2837
2534
|
/**
|
|
2838
2535
|
* 开启/关闭原生文件选择框拦截(CDP stateful 开关)。
|
|
2839
2536
|
*
|
|
@@ -2892,8 +2589,9 @@ Last error: ${lastError.message}` : "";
|
|
|
2892
2589
|
}
|
|
2893
2590
|
};
|
|
2894
2591
|
this._emit("dialog", dialog);
|
|
2592
|
+
const autoAccept = p.type === "beforeunload" ? this._beforeUnloadAccept : false;
|
|
2895
2593
|
setTimeout(() => {
|
|
2896
|
-
this.conn.send("Page.handleJavaScriptDialog", { accept:
|
|
2594
|
+
this.conn.send("Page.handleJavaScriptDialog", { accept: autoAccept }, this.sessionId).catch(() => {
|
|
2897
2595
|
});
|
|
2898
2596
|
}, 0);
|
|
2899
2597
|
})
|
|
@@ -3036,6 +2734,7 @@ Last error: ${lastError.message}` : "";
|
|
|
3036
2734
|
_networkRequests = /* @__PURE__ */ new Map();
|
|
3037
2735
|
_routeHandlers = [];
|
|
3038
2736
|
_interceptionEnabled = false;
|
|
2737
|
+
_beforeUnloadAccept = true;
|
|
3039
2738
|
/** Store network data — called by browser.ts installNetworkCapture or internal event handlers */
|
|
3040
2739
|
_storeNetworkRequest(requestId, data) {
|
|
3041
2740
|
this._networkRequests.set(requestId, { requestId, ...data });
|
|
@@ -3147,7 +2846,10 @@ Last error: ${lastError.message}` : "";
|
|
|
3147
2846
|
if (!this._interceptionEnabled) {
|
|
3148
2847
|
this._interceptionEnabled = true;
|
|
3149
2848
|
await this.conn.send("Fetch.enable", {
|
|
3150
|
-
patterns: [{ urlPattern: "*", requestStage: "Request" }]
|
|
2849
|
+
patterns: [{ urlPattern: "*", requestStage: "Request" }],
|
|
2850
|
+
// sup-s9: 保留认证自动响应(Fetch.enable 为替换语义,不带此参数
|
|
2851
|
+
// 会顶掉 _init 的 auth 配置)
|
|
2852
|
+
handleAuthRequests: true
|
|
3151
2853
|
}, this.sessionId);
|
|
3152
2854
|
this._subscriptions.push(
|
|
3153
2855
|
this.conn.subscribe("Fetch.requestPaused", this.sessionId, (params) => {
|
|
@@ -3200,6 +2902,36 @@ Last error: ${lastError.message}` : "";
|
|
|
3200
2902
|
});
|
|
3201
2903
|
}
|
|
3202
2904
|
// ── setInputFiles ───────────────────────────────────────────
|
|
2905
|
+
/**
|
|
2906
|
+
* sup-s4: Dropzone 拖拽上传模拟——Dropzone/Uppy/自绘上传区只监听
|
|
2907
|
+
* dragover/drop(无 input[type=file] 可点),真实用户靠 OS 文件拖入
|
|
2908
|
+
* 触发,自动化无法产生 OS 拖拽。页内构造 DataTransfer+File,按拖放
|
|
2909
|
+
* 协议派发 dragenter/dragover/drop(bubbles+cancelable,坐标取目标
|
|
2910
|
+
* 中心)。
|
|
2911
|
+
*/
|
|
2912
|
+
async dropFiles(selector, payload) {
|
|
2913
|
+
await this.evaluate(`
|
|
2914
|
+
(function() {
|
|
2915
|
+
var el = ${queryJS(selector)};
|
|
2916
|
+
if (!el) throw new Error('drop target not found: ' + ${JSON.stringify(selector)});
|
|
2917
|
+
var b64 = ${JSON.stringify(payload.buffer.toString("base64"))};
|
|
2918
|
+
var bin = atob(b64);
|
|
2919
|
+
var buf = new Uint8Array(bin.length);
|
|
2920
|
+
for (var i = 0; i < bin.length; i++) buf[i] = bin.charCodeAt(i);
|
|
2921
|
+
var file = new File([buf], ${JSON.stringify(payload.name)}, { type: ${JSON.stringify(payload.mimeType)} });
|
|
2922
|
+
var dt = new DataTransfer();
|
|
2923
|
+
dt.items.add(file);
|
|
2924
|
+
var rect = el.getBoundingClientRect();
|
|
2925
|
+
var opts = {
|
|
2926
|
+
bubbles: true, cancelable: true,
|
|
2927
|
+
clientX: rect.x + rect.width / 2, clientY: rect.y + rect.height / 2,
|
|
2928
|
+
};
|
|
2929
|
+
el.dispatchEvent(new DragEvent('dragenter', Object.assign({ dataTransfer: dt }, opts)));
|
|
2930
|
+
el.dispatchEvent(new DragEvent('dragover', Object.assign({ dataTransfer: dt }, opts)));
|
|
2931
|
+
el.dispatchEvent(new DragEvent('drop', Object.assign({ dataTransfer: dt }, opts)));
|
|
2932
|
+
})()
|
|
2933
|
+
`);
|
|
2934
|
+
}
|
|
3203
2935
|
async setInputFiles(selector, files) {
|
|
3204
2936
|
const fileArr = Array.isArray(files) ? files : [files];
|
|
3205
2937
|
const fileList = fileArr.map((f) => ({
|
|
@@ -3346,6 +3078,14 @@ var XBContextImpl = class {
|
|
|
3346
3078
|
get stealthConfig() {
|
|
3347
3079
|
return this.options.stealthConfig;
|
|
3348
3080
|
}
|
|
3081
|
+
/** sup-s9: HTTP 认证凭证经 context 传给 page 层(authRequired 自动响应) */
|
|
3082
|
+
get httpCredentials() {
|
|
3083
|
+
return this.options.httpCredentials;
|
|
3084
|
+
}
|
|
3085
|
+
/** sup-s12: 自签/无效证书放行——经 context 传给 page 层(原为死字段) */
|
|
3086
|
+
get ignoreHTTPSErrors() {
|
|
3087
|
+
return this.options.ignoreHTTPSErrors;
|
|
3088
|
+
}
|
|
3349
3089
|
async newPage() {
|
|
3350
3090
|
if (this.closed) throw new Error("Context is closed");
|
|
3351
3091
|
const { targetId } = await this._browser._createTarget(this.contextId);
|
|
@@ -3575,7 +3315,7 @@ var XBBrowserImpl = class {
|
|
|
3575
3315
|
this._exitHandler = null;
|
|
3576
3316
|
}
|
|
3577
3317
|
if (this.childProcess) {
|
|
3578
|
-
const { killChrome: killChrome2 } = await import("./launcher-
|
|
3318
|
+
const { killChrome: killChrome2 } = await import("./launcher-IK2FKW6T.js");
|
|
3579
3319
|
await killChrome2(this.childProcess, this.tmpDir);
|
|
3580
3320
|
}
|
|
3581
3321
|
await this.conn.close();
|
|
@@ -3601,6 +3341,38 @@ var XBBrowserImpl = class {
|
|
|
3601
3341
|
} catch {
|
|
3602
3342
|
}
|
|
3603
3343
|
const context = new XBContextImpl(this.conn, contextId, this, opts);
|
|
3344
|
+
if (!this.cdpEndpoint && contextId !== "default") {
|
|
3345
|
+
const downloadDir = join(tmpdir(), "xbrowser-downloads");
|
|
3346
|
+
try {
|
|
3347
|
+
mkdirSync(downloadDir, { recursive: true });
|
|
3348
|
+
} catch {
|
|
3349
|
+
}
|
|
3350
|
+
await this.conn.send("Browser.setDownloadBehavior", {
|
|
3351
|
+
behavior: "allowAndName",
|
|
3352
|
+
downloadPath: downloadDir,
|
|
3353
|
+
eventsEnabled: false,
|
|
3354
|
+
browserContextId: contextId
|
|
3355
|
+
}, void 0, 1e4).catch(() => {
|
|
3356
|
+
});
|
|
3357
|
+
await this.conn.send("Browser.grantPermissions", {
|
|
3358
|
+
permissions: [
|
|
3359
|
+
"notifications",
|
|
3360
|
+
"geolocation",
|
|
3361
|
+
"clipboardReadWrite",
|
|
3362
|
+
"clipboardSanitizedWrite",
|
|
3363
|
+
"videoCapture",
|
|
3364
|
+
"audioCapture",
|
|
3365
|
+
"midi"
|
|
3366
|
+
],
|
|
3367
|
+
browserContextId: contextId
|
|
3368
|
+
}, void 0, 1e4).catch(() => {
|
|
3369
|
+
this.conn.send("Browser.grantPermissions", {
|
|
3370
|
+
permissions: ["notifications", "geolocation"],
|
|
3371
|
+
browserContextId: contextId
|
|
3372
|
+
}, void 0, 1e4).catch(() => {
|
|
3373
|
+
});
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3604
3376
|
context.on("page", (page) => {
|
|
3605
3377
|
this._emitter.emit("page", page);
|
|
3606
3378
|
});
|
|
@@ -3713,7 +3485,7 @@ var XBBrowserImpl = class {
|
|
|
3713
3485
|
if (pageTargets.length === 0 && httpFallbackUrl) {
|
|
3714
3486
|
console.log(`[discoverContexts] Target.getTargets returned ${targetInfos.length} targets (0 page type). Falling back to HTTP /json/list at ${httpFallbackUrl}`);
|
|
3715
3487
|
try {
|
|
3716
|
-
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-
|
|
3488
|
+
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-IK2FKW6T.js");
|
|
3717
3489
|
const httpPages = await getCDPTargets2(httpFallbackUrl);
|
|
3718
3490
|
console.log(`[discoverContexts] HTTP /json/list returned ${httpPages.length} pages`);
|
|
3719
3491
|
for (const p of httpPages) {
|
|
@@ -4137,21 +3909,27 @@ async function launch(options = {}) {
|
|
|
4137
3909
|
}
|
|
4138
3910
|
const conn = new CDPConnection(wsEndpoint);
|
|
4139
3911
|
await conn.ready();
|
|
3912
|
+
let stealthOpts;
|
|
3913
|
+
try {
|
|
3914
|
+
const bv = await conn.send("Browser.getVersion");
|
|
3915
|
+
const m = bv.product.match(/(\d+)\.(\d+)\.(\d+)\.(\d+)/);
|
|
3916
|
+
if (m && !options.stealthConfig?.uaChProfile) {
|
|
3917
|
+
const { deriveUaChProfileForBinary } = await import("./stealth-JOXGV34D.js");
|
|
3918
|
+
stealthOpts = { stealthConfig: { uaChProfile: deriveUaChProfileForBinary(m[0], m[1]) } };
|
|
3919
|
+
}
|
|
3920
|
+
} catch {
|
|
3921
|
+
}
|
|
3922
|
+
if (options.stealthConfig) {
|
|
3923
|
+
stealthOpts = {
|
|
3924
|
+
stealthConfig: { ...stealthOpts?.stealthConfig ?? {}, ...options.stealthConfig }
|
|
3925
|
+
};
|
|
3926
|
+
}
|
|
4140
3927
|
const httpEndpoint = options.cdpEndpoint && !options.cdpEndpoint.startsWith("ws") ? options.cdpEndpoint : void 0;
|
|
4141
|
-
const browser = new XBBrowserImpl(
|
|
4142
|
-
conn,
|
|
4143
|
-
childProcess,
|
|
4144
|
-
tmpDir,
|
|
4145
|
-
httpEndpoint,
|
|
4146
|
-
options.stealthConfig ? { stealthConfig: options.stealthConfig } : void 0
|
|
4147
|
-
);
|
|
3928
|
+
const browser = new XBBrowserImpl(conn, childProcess, tmpDir, httpEndpoint, stealthOpts);
|
|
4148
3929
|
return { browser, wsEndpoint };
|
|
4149
3930
|
}
|
|
4150
3931
|
|
|
4151
3932
|
export {
|
|
4152
|
-
rand,
|
|
4153
|
-
sleep,
|
|
4154
|
-
wheelDelta,
|
|
4155
3933
|
XBMouseImpl,
|
|
4156
3934
|
XBKeyboardImpl,
|
|
4157
3935
|
waitForActionable,
|