@xbrowser/cli 1.20.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-Y6B3NS4Q.js → browser-BVRFSUXU.js} +3 -2
- package/dist/{browser-NVC7MTML.js → browser-DSYUAE7H.js} +5 -5
- package/dist/{browser-PBBC7RAV.js → browser-Q67BJTI2.js} +6 -4
- package/dist/{cdp-driver-QYFA4QTP.js → cdp-driver-DC7EIUG5.js} +4 -3
- package/dist/{cdp-driver-Z2PLAO42.js → cdp-driver-T7D6H2RW.js} +368 -510
- package/dist/{cdp-driver-73F5CVH2.js → cdp-driver-WWO2UZDR.js} +4 -3
- package/dist/{chunk-76EKW7YJ.js → chunk-2Q3GQRUP.js} +3 -3
- package/dist/{chunk-UYEJ66VX.js → chunk-4OU37CXP.js} +387 -540
- package/dist/{chunk-H2A5JUK5.js → chunk-75DNUI6M.js} +9 -0
- package/dist/{chunk-FDU5BCPV.js → chunk-7OP2ISEY.js} +378 -540
- package/dist/{chunk-3FWLW7FS.js → chunk-A7NEA4PA.js} +39 -1
- package/dist/chunk-GYB5BOSP.js +602 -0
- package/dist/{chunk-T2KUVO4H.js → chunk-IFKJO2UR.js} +393 -546
- package/dist/{chunk-NODRQGOK.js → chunk-IR6C24P7.js} +97 -0
- package/dist/{chunk-3KZ34AUC.js → chunk-MYH6FIBZ.js} +2 -1
- package/dist/{chunk-75TLPVVZ.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/{chunk-A6LPGFAL.js → chunk-WYETQ5C7.js} +1 -1
- package/dist/cli.js +25 -13
- package/dist/daemon-main.js +20 -14
- package/dist/index.d.ts +136 -1
- package/dist/index.js +29 -18
- 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/{proxy-LUR4U5YF.js → proxy-NKCYE76M.js} +2 -2
- 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 +2 -1
- package/dist/session-replayer-SBYJXQZZ.js +0 -413
|
@@ -1,19 +1,30 @@
|
|
|
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";
|
|
8
16
|
import {
|
|
9
17
|
createRuleEngine
|
|
10
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-75DNUI6M.js";
|
|
11
19
|
import {
|
|
12
20
|
__require
|
|
13
21
|
} from "./chunk-KFQGP6VL.js";
|
|
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,496 +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
|
-
bezierCurvature: [0.35, 0.6],
|
|
27
|
-
noiseAmplitude: 5.5,
|
|
28
|
-
overshootRange: [6, 14],
|
|
29
|
-
aimPause: [80, 280],
|
|
30
|
-
pressDuration: [60, 140],
|
|
31
|
-
releaseDrift: [0.8, 2.5],
|
|
32
|
-
landingOffsetSmall: [0.3, 2.5],
|
|
33
|
-
landingOffsetLarge: [1.5, 7],
|
|
34
|
-
smallElementThreshold: 30,
|
|
35
|
-
typingRhythm: {
|
|
36
|
-
fastProb: 0.22,
|
|
37
|
-
fastRange: [25, 60],
|
|
38
|
-
normalRange: [50, 350],
|
|
39
|
-
pauseProb: 0.18,
|
|
40
|
-
pauseRange: [400, 1200]
|
|
41
|
-
},
|
|
42
|
-
keyPressDuration: [50, 110],
|
|
43
|
-
typoProbability: 0.06,
|
|
44
|
-
wheelPeak: 180,
|
|
45
|
-
wheelDecayRate: 0.4
|
|
46
|
-
};
|
|
47
|
-
function rand(min, max) {
|
|
48
|
-
return min + Math.random() * (max - min);
|
|
49
|
-
}
|
|
50
|
-
function sleep(ms) {
|
|
51
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
52
|
-
}
|
|
53
|
-
function cosineEase(t) {
|
|
54
|
-
return 0.5 - 0.5 * Math.cos(Math.PI * t);
|
|
55
|
-
}
|
|
56
|
-
function bezierTrajectory(x0, y0, x1, y1, config = DEFAULT_STEALTH_CONFIG) {
|
|
57
|
-
const dist = Math.hypot(x1 - x0, y1 - y0);
|
|
58
|
-
const n = Math.max(10, Math.min(28, Math.round(dist / 15)));
|
|
59
|
-
const shortMove = dist < 120;
|
|
60
|
-
const curvature = shortMove ? rand(2, 6) : Math.max(dist * rand(...config.bezierCurvature), rand(18, 35));
|
|
61
|
-
const dir = Math.random() < 0.5 ? 1 : -1;
|
|
62
|
-
const d = dist || 1;
|
|
63
|
-
const dx = x1 - x0, dy = y1 - y0;
|
|
64
|
-
const c1x = x0 + dx * 0.3 - dy / d * curvature * 0.5 * dir;
|
|
65
|
-
const c1y = y0 + dy * 0.3 + dx / d * curvature * 0.5 * dir;
|
|
66
|
-
const c2x = x0 + dx * 0.7 - dy / d * curvature * 0.8 * dir;
|
|
67
|
-
const c2y = y0 + dy * 0.7 + dx / d * curvature * 0.8 * dir;
|
|
68
|
-
const points = [];
|
|
69
|
-
for (let i = 1; i <= n; i++) {
|
|
70
|
-
const t = cosineEase(i / n);
|
|
71
|
-
const mt = 1 - t;
|
|
72
|
-
let px = mt ** 3 * x0 + 3 * mt ** 2 * t * c1x + 3 * mt * t ** 2 * c2x + t ** 3 * x1;
|
|
73
|
-
let py = mt ** 3 * y0 + 3 * mt ** 2 * t * c1y + 3 * mt * t ** 2 * c2y + t ** 3 * y1;
|
|
74
|
-
const amp = shortMove ? Math.min(2, config.noiseAmplitude) : config.noiseAmplitude;
|
|
75
|
-
px += rand(-amp, amp);
|
|
76
|
-
py += rand(-amp, amp);
|
|
77
|
-
points.push({ x: px, y: py, delay: rand(9, 16) });
|
|
78
|
-
}
|
|
79
|
-
if (!shortMove) {
|
|
80
|
-
const over = rand(...config.overshootRange);
|
|
81
|
-
const ox = x1 + dx / d * over + rand(-2, 2);
|
|
82
|
-
const oy = y1 + dy / d * over + rand(-2, 2);
|
|
83
|
-
points.push({ x: ox, y: oy, delay: rand(14, 30) });
|
|
84
|
-
points.push({
|
|
85
|
-
x: x1 + dx / d * over * 0.4,
|
|
86
|
-
y: y1 + dy / d * over * 0.4,
|
|
87
|
-
delay: rand(14, 30)
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
points.push({ x: x1 + rand(-1, 1), y: y1 + rand(-1, 1), delay: rand(14, 30) });
|
|
91
|
-
return points;
|
|
92
|
-
}
|
|
93
|
-
function landingOffset(width, height, config = DEFAULT_STEALTH_CONFIG) {
|
|
94
|
-
const isSmall = Math.min(width, height) < config.smallElementThreshold;
|
|
95
|
-
const range = isSmall ? config.landingOffsetSmall : config.landingOffsetLarge;
|
|
96
|
-
const dx = rand(...range) * (Math.random() < 0.5 ? -1 : 1);
|
|
97
|
-
const dy = rand(...range) * (Math.random() < 0.5 ? -1 : 1);
|
|
98
|
-
return { dx, dy };
|
|
99
|
-
}
|
|
100
|
-
function typingDelay(config = DEFAULT_STEALTH_CONFIG) {
|
|
101
|
-
const roll = Math.random();
|
|
102
|
-
const r = config.typingRhythm;
|
|
103
|
-
if (roll < r.pauseProb) return rand(...r.pauseRange);
|
|
104
|
-
if (roll < r.pauseProb + r.fastProb) return rand(...r.fastRange);
|
|
105
|
-
return rand(...r.normalRange);
|
|
106
|
-
}
|
|
107
|
-
function wheelDelta(step, config = DEFAULT_STEALTH_CONFIG) {
|
|
108
|
-
return Math.round(
|
|
109
|
-
config.wheelPeak * Math.exp(-step * config.wheelDecayRate) * rand(0.85, 1.15)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
var KEY_MAP = {};
|
|
113
|
-
for (let i = 97; i <= 122; i++) {
|
|
114
|
-
const ch = String.fromCharCode(i);
|
|
115
|
-
KEY_MAP[ch] = { key: ch, code: "Key" + ch.toUpperCase(), vk: i - 32 };
|
|
116
|
-
}
|
|
117
|
-
for (let i = 65; i <= 90; i++) {
|
|
118
|
-
const ch = String.fromCharCode(i);
|
|
119
|
-
KEY_MAP[ch] = { key: ch, code: "Key" + ch, vk: i, shift: true };
|
|
120
|
-
}
|
|
121
|
-
for (let i = 48; i <= 57; i++) {
|
|
122
|
-
const ch = String.fromCharCode(i);
|
|
123
|
-
KEY_MAP[ch] = { key: ch, code: "Digit" + ch, vk: i };
|
|
124
|
-
}
|
|
125
|
-
Object.assign(KEY_MAP, {
|
|
126
|
-
" ": { key: " ", code: "Space", vk: 32 },
|
|
127
|
-
".": { key: ".", code: "Period", vk: 190 },
|
|
128
|
-
"-": { key: "-", code: "Minus", vk: 189 },
|
|
129
|
-
"@": { key: "@", code: "Digit2", vk: 50, shift: true },
|
|
130
|
-
"_": { key: "_", code: "Minus", vk: 189, shift: true }
|
|
131
|
-
});
|
|
132
|
-
function buildStealthInitScript() {
|
|
133
|
-
return [
|
|
134
|
-
"(function(){",
|
|
135
|
-
' window.__xbStealthVer="57";',
|
|
136
|
-
// 1. AEL event proxy
|
|
137
|
-
" var o=EventTarget.prototype.addEventListener;",
|
|
138
|
-
" var fc=new InputDeviceCapabilities({firesTouchEvents:false});",
|
|
139
|
-
" var _ael=function(t,f){",
|
|
140
|
-
" var op=arguments[2];",
|
|
141
|
-
' if(typeof f!=="function")return o.call(this,t,f,op);',
|
|
142
|
-
" var w=function(e){",
|
|
143
|
-
" if(!e)return f.call(this,e);",
|
|
144
|
-
" return f.call(this,new Proxy(e,{get:function(k,p){",
|
|
145
|
-
' if(p==="sourceCapabilities")return fc;',
|
|
146
|
-
// S124 修正(d67 攻防):恒 true 是"过度伪装"——站点自己的合成事件
|
|
147
|
-
// 也变 true → 直接判定浏览器被篡改(比检测自动化更严重的指纹暴露)。
|
|
148
|
-
// 正确策略:透传原始值(CDP Input 事件本来就是 true,JS 合成本来是 false)
|
|
149
|
-
// + paste 定向伪装(合成的 paste 在真实场景都是 trusted 的键盘操作产物)
|
|
150
|
-
' if(p==="isTrusted"){',
|
|
151
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
152
|
-
" if(orig===true)return true;",
|
|
153
|
-
' if(k.type==="paste")return true;',
|
|
154
|
-
" return orig;",
|
|
155
|
-
" }",
|
|
156
|
-
' if((p==="clientX"||p==="clientY")&&k.type==="click"&&Number.isInteger(k[p])){',
|
|
157
|
-
" var _f=((k.timeStamp||Date.now())%89)/89*0.7+0.15;",
|
|
158
|
-
" return k[p]+_f;",
|
|
159
|
-
" }",
|
|
160
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
161
|
-
" }}));",
|
|
162
|
-
" };",
|
|
163
|
-
" return o.call(this,t,w,op);",
|
|
164
|
-
" };",
|
|
165
|
-
" EventTarget.prototype.addEventListener=_ael;",
|
|
166
|
-
// window.event isTrusted 伪装(S123):AEL 参数包装收不到 window.event
|
|
167
|
-
// (它是原始 Event 对象的隐式引用)。定义 getter 拦截读取。
|
|
168
|
-
" try{",
|
|
169
|
-
' var _weDesc=Object.getOwnPropertyDescriptor(Window.prototype,"event");',
|
|
170
|
-
" if(_weDesc&&_weDesc.get){",
|
|
171
|
-
" var _origWeGet=_weDesc.get;",
|
|
172
|
-
' Object.defineProperty(Window.prototype,"event",{',
|
|
173
|
-
" configurable:true,",
|
|
174
|
-
" get:function(){",
|
|
175
|
-
" var ev=_origWeGet.call(this);",
|
|
176
|
-
" if(!ev)return ev;",
|
|
177
|
-
" return new Proxy(ev,{get:function(k,p){",
|
|
178
|
-
' if(p==="isTrusted"){',
|
|
179
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
180
|
-
" if(orig===true)return true;",
|
|
181
|
-
' if(k.type==="paste")return true;',
|
|
182
|
-
" return orig;",
|
|
183
|
-
" }",
|
|
184
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
185
|
-
" }});",
|
|
186
|
-
" }",
|
|
187
|
-
" });",
|
|
188
|
-
" }",
|
|
189
|
-
" }catch(e){}",
|
|
190
|
-
// 2. Screen override (prototype-level, not instance-level)
|
|
191
|
-
" var _gw=function(){return 1728};",
|
|
192
|
-
" var _gh=function(){return 1117};",
|
|
193
|
-
" var _gah=function(){return 1092};",
|
|
194
|
-
' Object.defineProperty(Screen.prototype,"width",{get:_gw,configurable:true});',
|
|
195
|
-
' Object.defineProperty(Screen.prototype,"height",{get:_gh,configurable:true});',
|
|
196
|
-
' Object.defineProperty(Screen.prototype,"availWidth",{get:_gw,configurable:true});',
|
|
197
|
-
' Object.defineProperty(Screen.prototype,"availHeight",{get:_gah,configurable:true});',
|
|
198
|
-
// S174: UA Headless 标记清洗——headless launch 的 UA 含 HeadlessChrome/xxx
|
|
199
|
-
// (最高频检测面),同步清洗 userAgent/appVersion/userAgentData(brands+高熵值)。
|
|
200
|
-
// 原型+实例双层覆写(S172 模式)。
|
|
201
|
-
" try{",
|
|
202
|
-
' var fixUA=function(ua){return String(ua).replace("HeadlessChrome","Chrome");};',
|
|
203
|
-
' 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;});};',
|
|
204
|
-
' var _nuad=Object.getOwnPropertyDescriptor(Navigator.prototype,"userAgentData");',
|
|
205
|
-
" var wrapUAD=function(uad){",
|
|
206
|
-
" if(!uad||uad.__xbUA)return uad;",
|
|
207
|
-
" try{",
|
|
208
|
-
' Object.defineProperty(uad,"brands",{get:function(){return fixBrands(_nuad.get.call(navigator).brands);},configurable:true});',
|
|
209
|
-
" var _ghev=uad.getHighEntropyValues.bind(uad);",
|
|
210
|
-
" uad.getHighEntropyValues=function(hints){return _ghev(hints).then(function(v){",
|
|
211
|
-
' 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]);}',
|
|
212
|
-
" return o;});};",
|
|
213
|
-
" uad.__xbUA=true;",
|
|
214
|
-
" }catch(e){}",
|
|
215
|
-
" return uad;",
|
|
216
|
-
" };",
|
|
217
|
-
' var _nua=Object.getOwnPropertyDescriptor(Navigator.prototype,"userAgent");',
|
|
218
|
-
" if(_nua&&_nua.get){",
|
|
219
|
-
" var _nuag=function(){return fixUA(_nua.get.call(this));};",
|
|
220
|
-
' _nuag.toString=function(){return "function get userAgent() { [native code] }";};',
|
|
221
|
-
' Object.defineProperty(Navigator.prototype,"userAgent",{get:_nuag,configurable:true});',
|
|
222
|
-
" }",
|
|
223
|
-
' Object.defineProperty(navigator,"userAgent",{get:function(){return fixUA(_nua?_nua.get.call(this):"");},configurable:true});',
|
|
224
|
-
" if(_nuad&&_nuad.get){",
|
|
225
|
-
" var _nuadg=function(){return wrapUAD(_nuad.get.call(this));};",
|
|
226
|
-
' _nuadg.toString=function(){return "function get userAgentData() { [native code] }";};',
|
|
227
|
-
' Object.defineProperty(Navigator.prototype,"userAgentData",{get:_nuadg,configurable:true});',
|
|
228
|
-
" }",
|
|
229
|
-
" }catch(e){}",
|
|
230
|
-
// hasFocus 与 visibilityState 联动(d29):恒 true 在 hidden 标签下暴露
|
|
231
|
-
// —— 真实浏览器失焦/后台时 hasFocus=false
|
|
232
|
-
// S172: 原型层覆写——实例赋值可被 Document.prototype.hasFocus.call(document) 逃逸
|
|
233
|
-
' Document.prototype.hasFocus=function(){return document.visibilityState==="visible";};',
|
|
234
|
-
// 4. Canvas/WebGL fingerprint: per-session stable noise (d20).
|
|
235
|
-
// Headless software raster differs subtly from Chrome GPU raster —
|
|
236
|
-
// toDataURL hashes fingerprint the rasterizer. Inject a stable
|
|
237
|
-
// (per-page-load) subpixel shift into fillText so hashes look like a
|
|
238
|
-
// distinct-but-consistent real GPU, and hide the HEADLESS tell in
|
|
239
|
-
// WebGL renderer strings.
|
|
240
|
-
" var _seed=Math.floor(Math.random()*2147483647);",
|
|
241
|
-
" var _prng=function(){_seed=(_seed*48271)%2147483647;return _seed/2147483647;};",
|
|
242
|
-
" var _dx=(_prng()*0.4-0.2).toFixed(3)*1, _dy=(_prng()*0.4-0.2).toFixed(3)*1;",
|
|
243
|
-
" var _fillText=CanvasRenderingContext2D.prototype.fillText;",
|
|
244
|
-
" CanvasRenderingContext2D.prototype.fillText=function(t,x,y,m){",
|
|
245
|
-
" return _fillText.call(this,t,x+_dx,y+_dy,m);",
|
|
246
|
-
" };",
|
|
247
|
-
" var _toDataURL=HTMLCanvasElement.prototype.toDataURL;",
|
|
248
|
-
" HTMLCanvasElement.prototype.toDataURL=function(){",
|
|
249
|
-
' var ctx=this.getContext("2d");',
|
|
250
|
-
" if(ctx){var d=ctx.getImageData(0,0,Math.min(this.width,2),Math.min(this.height,2));",
|
|
251
|
-
" for(var i=0;i<d.data.length;i+=4){if(d.data[i+3]>0){d.data[i]^=1;break;}}",
|
|
252
|
-
" ctx.putImageData(d,0,0);}",
|
|
253
|
-
" return _toDataURL.apply(this,arguments);",
|
|
254
|
-
" };",
|
|
255
|
-
" try{",
|
|
256
|
-
" var _gl=HTMLCanvasElement.prototype.getContext;",
|
|
257
|
-
" HTMLCanvasElement.prototype.getContext=function(t,o){",
|
|
258
|
-
" var c=_gl.call(this,t,o);",
|
|
259
|
-
' if(c&&(t==="webgl"||t==="experimental-webgl")&&c.getParameter){',
|
|
260
|
-
" var _gp=c.getParameter.bind(c);",
|
|
261
|
-
" c.getParameter=function(p){",
|
|
262
|
-
" var v=_gp(p);",
|
|
263
|
-
' if(typeof v==="string"&&/SwiftShader|Software|Rasterizer|Headless/i.test(v))',
|
|
264
|
-
' return "ANGLE (Apple, ANGLE Metal Renderer: Apple M2 Max, Unspecified Version)";',
|
|
265
|
-
" return v;};}",
|
|
266
|
-
" return c;};",
|
|
267
|
-
" }catch(e){}",
|
|
268
|
-
// 5. AudioContext fingerprint: per-load stable micro-noise on channel
|
|
269
|
-
// data (d21). DSP sum differences between headless software audio and
|
|
270
|
-
// real hardware audio are a classic fingerprint — add ±1e-7 level
|
|
271
|
-
// noise (inaudible, changes the sum hash).
|
|
272
|
-
" try{",
|
|
273
|
-
" var _gcd=AudioBuffer.prototype.getChannelData;",
|
|
274
|
-
" AudioBuffer.prototype.getChannelData=function(ch){",
|
|
275
|
-
" var d=_gcd.call(this,ch);",
|
|
276
|
-
' var key="__xb_audio_"+ch;',
|
|
277
|
-
" if(!this[key]){",
|
|
278
|
-
" this[key]=true;",
|
|
279
|
-
" for(var i=0;i<d.length;i+=997){d[i]=d[i]+(_prng()-0.5)*2e-7;}",
|
|
280
|
-
" }",
|
|
281
|
-
" return d;",
|
|
282
|
-
" };",
|
|
283
|
-
" var _gffd=AnalyserNode.prototype.getFloatFrequencyData;",
|
|
284
|
-
" AnalyserNode.prototype.getFloatFrequencyData=function(arr){",
|
|
285
|
-
" _gffd.call(this,arr);",
|
|
286
|
-
" for(var i=0;i<arr.length;i+=31){arr[i]=arr[i]+(_prng()-0.5)*0.01;}",
|
|
287
|
-
" };",
|
|
288
|
-
" var _gfbd=AnalyserNode.prototype.getByteFrequencyData;",
|
|
289
|
-
" AnalyserNode.prototype.getByteFrequencyData=function(arr){",
|
|
290
|
-
" _gfbd.call(this,arr);",
|
|
291
|
-
" for(var i=0;i<arr.length;i+=31){arr[i]=(arr[i]+((_prng()*3)|0))&255;}",
|
|
292
|
-
" };",
|
|
293
|
-
" }catch(e){}",
|
|
294
|
-
// 3b. Font metrics + speechSynthesis + battery (d22): headless tells
|
|
295
|
-
" try{",
|
|
296
|
-
' var _tmw=Object.getOwnPropertyDescriptor(TextMetrics.prototype,"width");',
|
|
297
|
-
" if(_tmw&&_tmw.get){",
|
|
298
|
-
" // S172: \u539F\u578B\u5C42\u8986\u5199\u2014\u2014\u5B9E\u4F8B(m)\u8986\u5199\u53EF\u88AB TextMetrics.prototype.width getter \u9003\u9038",
|
|
299
|
-
' Object.defineProperty(TextMetrics.prototype,"width",{get:function(){return _tmw.get.call(this)+_dx*0.01;},configurable:true});',
|
|
300
|
-
" }",
|
|
301
|
-
" }catch(e){}",
|
|
302
|
-
" try{",
|
|
303
|
-
' var _fakeVoices=["Alex","Daniel","Karen","Moira","Ralph","Samantha","Ting-Ting","Mei-Jia","Sinji","Yunda"];',
|
|
304
|
-
// S172: 原型层覆写——实例赋值可被 SpeechSynthesis.prototype.getVoices.call() 逃逸
|
|
305
|
-
" var _sv=SpeechSynthesis.prototype.getVoices;",
|
|
306
|
-
" SpeechSynthesis.prototype.getVoices=function(){",
|
|
307
|
-
" var real=_sv.call(this);",
|
|
308
|
-
" if(real&&real.length>50)return real;",
|
|
309
|
-
// 注意阈值从 0 改 50:iframe 原生约 10 个 —— 原阈值下 iframe 返回原生 10 个
|
|
310
|
-
// 而不是伪装 180(d33 暴露)。>50 = 主文档伪装列表已生效,其余返回伪装。
|
|
311
|
-
' 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};});',
|
|
312
|
-
" };",
|
|
313
|
-
// d33 修复:iframe 的 speechSynthesis 是独立实例(主文档 hook 不可达)——
|
|
314
|
-
// 轮询同源 iframe,对其 contentWindow 的原型同样 patch(S172: 原型层,防逃逸)
|
|
315
|
-
" try{",
|
|
316
|
-
" var _piv=function(){",
|
|
317
|
-
' var frs=document.querySelectorAll("iframe");',
|
|
318
|
-
" for(var i=0;i<frs.length;i++){try{",
|
|
319
|
-
" var cw=frs[i].contentWindow;",
|
|
320
|
-
" if(!cw||!cw.speechSynthesis||cw.speechSynthesis.__xbP)continue;",
|
|
321
|
-
" cw.speechSynthesis.__xbP=true;",
|
|
322
|
-
" var _sv2=cw.SpeechSynthesis.prototype.getVoices;",
|
|
323
|
-
" cw.SpeechSynthesis.prototype.getVoices=function(){var r=_sv2.call(this);if(r&&r.length>50)return r;",
|
|
324
|
-
' 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};});};',
|
|
325
|
-
" }catch(e2){}}",
|
|
326
|
-
" };",
|
|
327
|
-
" setInterval(_piv,2000);",
|
|
328
|
-
" var _mo=new MutationObserver(function(muts){",
|
|
329
|
-
" for(var k=0;k<muts.length;k++){var ns=muts[k].addedNodes;",
|
|
330
|
-
' for(var q=0;q<ns.length;q++){if(ns[q].tagName==="IFRAME")setTimeout(_piv,20);}}',
|
|
331
|
-
" });",
|
|
332
|
-
" _mo.observe(document.documentElement,{childList:true,subtree:true});",
|
|
333
|
-
" }catch(e){}",
|
|
334
|
-
" }catch(e){}",
|
|
335
|
-
" try{",
|
|
336
|
-
" var _gb=navigator.getBattery.bind(navigator);",
|
|
337
|
-
" navigator.getBattery=function(){",
|
|
338
|
-
" return _gb().then(function(b){",
|
|
339
|
-
' Object.defineProperty(b,"charging",{get:function(){return true;},configurable:true});',
|
|
340
|
-
" return b;});",
|
|
341
|
-
" };",
|
|
342
|
-
" }catch(e){}",
|
|
343
|
-
// 3c. WebRTC local IP leak guard (d23): headless STUN candidates can
|
|
344
|
-
// expose host IPs; mDNS-only candidates are the modern Chrome default.
|
|
345
|
-
" try{",
|
|
346
|
-
" var _oc=RTCPeerConnection.prototype.createOffer;",
|
|
347
|
-
" RTCPeerConnection.prototype.createOffer=function(){",
|
|
348
|
-
" var p=_oc.apply(this,arguments);",
|
|
349
|
-
" var self=this;",
|
|
350
|
-
" return p.then(function(offer){",
|
|
351
|
-
' offer.sdp=offer.sdp.split(String.fromCharCode(10)).filter(function(l){return l.indexOf("typ host")<0}).join(String.fromCharCode(10));',
|
|
352
|
-
" return offer;});",
|
|
353
|
-
" };",
|
|
354
|
-
" }catch(e){}",
|
|
355
|
-
// 3d-2. performance.now precision clamp (d34): full-precision timestamps
|
|
356
|
-
// (11 decimals) differ from site-isolation-clamped real Chrome (~100μs).
|
|
357
|
-
" try{",
|
|
358
|
-
" var _pn=Performance.prototype.now;",
|
|
359
|
-
" // S172: \u539F\u578B\u5C42\u8986\u5199\u2014\u2014\u5B9E\u4F8B\u8D4B\u503C\u53EF\u88AB Performance.prototype.now.call(performance) \u9003\u9038",
|
|
360
|
-
" Performance.prototype.now=function(){return Math.round(_pn.call(this)*10)/10;};",
|
|
361
|
-
' var _pto=Object.getOwnPropertyDescriptor(Performance.prototype,"timeOrigin");',
|
|
362
|
-
" if(_pto&&_pto.get){",
|
|
363
|
-
" // 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",
|
|
364
|
-
" // \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",
|
|
365
|
-
" // \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",
|
|
366
|
-
" var _toff=Math.floor((_seed/2147483647)*600000-300000);",
|
|
367
|
-
" var _tog=function(){return _pto.get.call(performance)+_toff;};",
|
|
368
|
-
' _tog.toString=function(){return "function get timeOrigin() { [native code] }";};',
|
|
369
|
-
" // S172 \u5BA1\u8BA1\uFF1A\u5B9E\u4F8B\u8986\u5199\u53EF\u88AB\u539F\u578B getter \u9003\u9038\u2014\u2014\u539F\u578B\u5C42\u8986\u5199",
|
|
370
|
-
' Object.defineProperty(Performance.prototype,"timeOrigin",{get:_tog,configurable:true});',
|
|
371
|
-
' Object.defineProperty(performance,"timeOrigin",{get:_tog,configurable:true});',
|
|
372
|
-
" }",
|
|
373
|
-
" }catch(e){}",
|
|
374
|
-
// 3f. getCoalescedEvents 合成(d47):真实鼠标 125Hz 采样被浏览器按帧合并,
|
|
375
|
-
// 快速移动时 pointermove.getCoalescedEvents() 返回 2~6 个事件(群内
|
|
376
|
-
// ≈8ms);CDP Input 逐事件派发不走合并管线,coalesced>1 恒为 0(结构性
|
|
377
|
-
// 暴露,间隔模拟救不了——实测 Chrome 帧对齐时 CDP 连发事件被直接丢弃
|
|
378
|
-
// 而非合并)。按 125Hz 物理插值合成 coalesced 群:期望样本数 = dt/8ms-1,
|
|
379
|
-
// 合成事件用真 PointerEvent 构造 + 实例级 isTrusted/timeStamp 遮蔽。
|
|
380
|
-
" try{",
|
|
381
|
-
" if(window.PointerEvent&&PointerEvent.prototype.getCoalescedEvents){",
|
|
382
|
-
" var _gce=PointerEvent.prototype.getCoalescedEvents;",
|
|
383
|
-
" var _lm=null;",
|
|
384
|
-
" var _gceH=function(){",
|
|
385
|
-
" var list=_gce.call(this);",
|
|
386
|
-
' if(this.type!=="pointermove"||!this.isTrusted)return list;',
|
|
387
|
-
" var cur={x:this.clientX,y:this.clientY,ts:this.timeStamp};",
|
|
388
|
-
" var out=null;",
|
|
389
|
-
" if((!list||list.length<2)&&_lm){",
|
|
390
|
-
" var dt=cur.ts-_lm.ts,dx=cur.x-_lm.x,dy=cur.y-_lm.y;",
|
|
391
|
-
// dt 长(帧丢弃后)不代表群覆盖整个 dt —— 真实 coalesced 群只覆盖
|
|
392
|
-
// 最后一帧窗口(≤16.7ms,群内 ≈8ms=125Hz)。合成群从自身往回推 8ms
|
|
393
|
-
// 链,位移取末端占比(span/dt,dt 远大于 span 时位移趋零=丢弃后实况)。
|
|
394
|
-
" var expN=Math.floor(dt/8)-1;",
|
|
395
|
-
// dt<12ms(不足一帧+采样周期)时真实浏览器不会产生合并群 ——
|
|
396
|
-
// 单采样帧 coalesced=1,强行合成会出现 ~2ms 的超物理群内间隔。
|
|
397
|
-
" if(expN>0&&dt>=12&&Math.random()>0.15){",
|
|
398
|
-
" var n=Math.min(4,expN+(Math.random()<0.3?1:0));",
|
|
399
|
-
" var span=Math.min(dt,n*8.3);",
|
|
400
|
-
" var frac=Math.min(1,span/Math.max(dt,1));",
|
|
401
|
-
" out=[];",
|
|
402
|
-
" for(var i=1;i<=n;i++){",
|
|
403
|
-
// k=距自身的步数(含自身共 n+1 个事件,相邻恒 ≈8.3ms=125Hz 周期)
|
|
404
|
-
" var k=n+1-i;",
|
|
405
|
-
' var ev=new PointerEvent("pointermove",{',
|
|
406
|
-
' pointerId:this.pointerId,pointerType:"mouse",isPrimary:this.isPrimary,',
|
|
407
|
-
" clientX:cur.x-dx*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
408
|
-
" clientY:cur.y-dy*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
409
|
-
" screenX:this.screenX,screenY:this.screenY,",
|
|
410
|
-
" buttons:this.buttons,button:this.button,",
|
|
411
|
-
" bubbles:true,cancelable:true,composed:true,",
|
|
412
|
-
" width:this.width,height:this.height,pressure:this.pressure,",
|
|
413
|
-
" tiltX:this.tiltX,tiltY:this.tiltY,twist:this.twist});",
|
|
414
|
-
" var tsV=cur.ts-k*8.3-Math.random()*1.2;",
|
|
415
|
-
// isTrusted/timeStamp 是实例不可配置属性(defineProperty 抛
|
|
416
|
-
// "Cannot redefine"),改 Proxy 包装:getPrototypeOf/ownKeys 透传,
|
|
417
|
-
// instanceof 与属性枚举行为与真事件一致。IIFE 捕获本次循环的 tsV
|
|
418
|
-
// 快照 —— var 提升会让所有 Proxy 闭包共享最后一次赋值(实测四个
|
|
419
|
-
// 合成事件同时间戳、群内间隔塌到 ~2ms)。
|
|
420
|
-
" out.push((function(e2,t2){return new Proxy(e2,{get:function(t,p){",
|
|
421
|
-
' if(p==="isTrusted")return true;',
|
|
422
|
-
' if(p==="timeStamp")return t2;',
|
|
423
|
-
' var v=Reflect.get(t,p);return typeof v==="function"?v.bind(t):v;',
|
|
424
|
-
" }});})(ev,tsV));",
|
|
425
|
-
" }",
|
|
426
|
-
" out.push(this);",
|
|
427
|
-
" }",
|
|
428
|
-
" }",
|
|
429
|
-
" _lm=cur;",
|
|
430
|
-
" return out||list;",
|
|
431
|
-
" };",
|
|
432
|
-
" PointerEvent.prototype.getCoalescedEvents=_gceH;",
|
|
433
|
-
// name 反查伪装:var _gceH=fn 的具名推断会暴露 hook(原生 name 是
|
|
434
|
-
// "getCoalescedEvents")——toString 白名单管不到 name 属性。
|
|
435
|
-
' try{Object.defineProperty(_gceH,"name",{value:"getCoalescedEvents"});}catch(e){}',
|
|
436
|
-
" }",
|
|
437
|
-
" }catch(e){}",
|
|
438
|
-
// 3d. Chrome object depth (d24): automation fakes usually only set
|
|
439
|
-
// window.chrome = {}; deep checks hit app.run/runtime/csi/loadTimes.
|
|
440
|
-
" try{",
|
|
441
|
-
" if(window.chrome){",
|
|
442
|
-
' 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"}};',
|
|
443
|
-
' 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};',
|
|
444
|
-
" if(!window.chrome.csi)window.chrome.csi=function(){return{};}",
|
|
445
|
-
" if(!window.chrome.loadTimes)window.chrome.loadTimes=function(){return{};}",
|
|
446
|
-
" }",
|
|
447
|
-
" }catch(e){}",
|
|
448
|
-
// 3e. Font availability patch (d25): headless Chromium misses some system
|
|
449
|
-
// fonts (e.g. Menlo on macOS) that real Chrome has. Register a FontFace
|
|
450
|
-
// aliasing the missing font to a local() equivalent so offsetWidth-based
|
|
451
|
-
// font probing sees the same availability as the faked environment.
|
|
452
|
-
" try{",
|
|
453
|
-
' var _fontAliases=[["Menlo","Courier New"],["SF Mono","Menlo"],["Segoe UI","Helvetica"]];',
|
|
454
|
-
" _fontAliases.forEach(function(pa){",
|
|
455
|
-
' try{var ff=new FontFace(pa[0],"local("+JSON.stringify(pa[1])+")");',
|
|
456
|
-
" document.fonts.add(ff);ff.load();}catch(e2){}",
|
|
457
|
-
" });",
|
|
458
|
-
" }catch(e){}",
|
|
459
|
-
// 3g. Notification.requestPermission 延迟(d62):headless 无原生横幅,
|
|
460
|
-
// request 瞬回 denied —— 真机 request 会 pending 在横幅上数秒到分钟。
|
|
461
|
-
// 延迟 2-6s 再 resolve,模拟横幅期(用户"看了下然后拒绝")。
|
|
462
|
-
" try{",
|
|
463
|
-
" if(window.Notification&&Notification.requestPermission){",
|
|
464
|
-
" var _nrp=Notification.requestPermission.bind(Notification);",
|
|
465
|
-
" Notification.requestPermission=function(cb){",
|
|
466
|
-
" return new Promise(function(res){",
|
|
467
|
-
" setTimeout(function(){_nrp().then(function(r){if(cb)try{cb(r)}catch(e){}res(r);});},2000+Math.random()*4000);",
|
|
468
|
-
" });",
|
|
469
|
-
" };",
|
|
470
|
-
" }",
|
|
471
|
-
" }catch(e){}",
|
|
472
|
-
// 3. toString disguise (name-list based)
|
|
473
|
-
" var _ts=Function.prototype.toString;",
|
|
474
|
-
" var _hf=document.hasFocus;",
|
|
475
|
-
" Function.prototype.toString=function(){",
|
|
476
|
-
' if(this===_ael)return"function addEventListener(type, callback) { [native code] }";',
|
|
477
|
-
' if(this===_hf)return"function hasFocus() { [native code] }";',
|
|
478
|
-
' if(this===_gw)return"function get width() { [native code] }";',
|
|
479
|
-
' if(this===_gh)return"function get height() { [native code] }";',
|
|
480
|
-
' if(this===_gah)return"function get availHeight() { [native code] }";',
|
|
481
|
-
' if(this===CanvasRenderingContext2D.prototype.fillText)return"function fillText() { [native code] }";',
|
|
482
|
-
' if(this===HTMLCanvasElement.prototype.toDataURL)return"function toDataURL() { [native code] }";',
|
|
483
|
-
' if(this===AnalyserNode.prototype.getFloatFrequencyData)return"function getFloatFrequencyData() { [native code] }";',
|
|
484
|
-
' if(this===AudioBuffer.prototype.getChannelData)return"function getChannelData() { [native code] }";',
|
|
485
|
-
' if(this===_gceH)return"function getCoalescedEvents() { [native code] }";',
|
|
486
|
-
' if(this===Document.prototype.hasFocus)return"function hasFocus() { [native code] }";',
|
|
487
|
-
' if(this===Performance.prototype.now)return"function now() { [native code] }";',
|
|
488
|
-
' if(this===SpeechSynthesis.prototype.getVoices)return"function getVoices() { [native code] }";',
|
|
489
|
-
" return _ts.call(this);",
|
|
490
|
-
" };",
|
|
491
|
-
// 4. onclick prototype hijack (dual-stream consistency)
|
|
492
|
-
" var _ba=function(k,p){",
|
|
493
|
-
' if(p==="isTrusted"){',
|
|
494
|
-
' var orig=Reflect.get(k,"isTrusted");',
|
|
495
|
-
" if(orig===true)return true;",
|
|
496
|
-
' if(k.type==="paste")return true;',
|
|
497
|
-
" return orig;",
|
|
498
|
-
" }",
|
|
499
|
-
' if((p==="clientX"||p==="clientY")&&k.type==="click"&&Number.isInteger(k[p])&&k.isTrusted===true){',
|
|
500
|
-
" var _f=((k.timeStamp||Date.now())%89)/89*0.7+0.15;return k[p]+_f;",
|
|
501
|
-
" }",
|
|
502
|
-
' var v=Reflect.get(k,p);return typeof v==="function"?v.bind(k):v;',
|
|
503
|
-
" };",
|
|
504
|
-
' Object.defineProperty(Document.prototype,"onclick",{',
|
|
505
|
-
" configurable:true,",
|
|
506
|
-
" get:function(){var raw=this.__ocRaw||null;if(!raw)return null;var self=this;",
|
|
507
|
-
" return function(e){return raw.call(self,new Proxy(e,{get:function(k,p){return _ba(k,p)}}))}},",
|
|
508
|
-
" set:function(fn){this.__ocRaw=fn}",
|
|
509
|
-
" });",
|
|
510
|
-
"})()"
|
|
511
|
-
].join("\n");
|
|
512
|
-
}
|
|
513
|
-
|
|
514
35
|
// src/cdp-driver/mouse.ts
|
|
515
36
|
var XBMouseImpl = class {
|
|
516
37
|
conn;
|
|
@@ -551,26 +72,26 @@ var XBMouseImpl = class {
|
|
|
551
72
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: p.x, y: p.y, button: this._button });
|
|
552
73
|
this._x = p.x;
|
|
553
74
|
this._y = p.y;
|
|
554
|
-
await
|
|
75
|
+
await sleep(p.delay);
|
|
555
76
|
}
|
|
556
77
|
this._x = tx;
|
|
557
78
|
this._y = ty;
|
|
558
79
|
if (_truncated) {
|
|
559
80
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: tx, y: ty, button: this._button });
|
|
560
81
|
}
|
|
561
|
-
await
|
|
82
|
+
await sleep(rand(...DEFAULT_STEALTH_CONFIG.aimPause));
|
|
562
83
|
} else {
|
|
563
84
|
await this.move(tx, ty);
|
|
564
85
|
}
|
|
565
|
-
await this.down({ button });
|
|
566
|
-
await
|
|
86
|
+
await this.down({ button, clickCount: opts.clickCount ?? 1 });
|
|
87
|
+
await sleep(stealth ? rand(...DEFAULT_STEALTH_CONFIG.pressDuration) : opts.delay ?? 0);
|
|
567
88
|
const rx = stealth ? this._x + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._x;
|
|
568
89
|
const ry = stealth ? this._y + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._y;
|
|
569
90
|
this._x = rx;
|
|
570
91
|
this._y = ry;
|
|
571
92
|
await this.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: rx, y: ry, button, clickCount: opts.clickCount ?? 1 });
|
|
572
93
|
for (let i = 1; i < (opts.clickCount ?? 1); i++) {
|
|
573
|
-
if (opts.delay) await
|
|
94
|
+
if (opts.delay) await sleep(opts.delay);
|
|
574
95
|
await this.down({ button });
|
|
575
96
|
await this.up({ button });
|
|
576
97
|
}
|
|
@@ -586,7 +107,9 @@ var XBMouseImpl = class {
|
|
|
586
107
|
x: this._x,
|
|
587
108
|
y: this._y,
|
|
588
109
|
button,
|
|
589
|
-
|
|
110
|
+
// r23: press 必须与 release 声明同一 clickCount——Chrome 按序列计数
|
|
111
|
+
// 合成 click/dblclick,press 缺声明会把计数器重置(dblclick 永不合成)
|
|
112
|
+
clickCount: opts.clickCount ?? 1
|
|
590
113
|
});
|
|
591
114
|
}
|
|
592
115
|
async up(opts = {}) {
|
|
@@ -597,7 +120,7 @@ var XBMouseImpl = class {
|
|
|
597
120
|
x: this._x,
|
|
598
121
|
y: this._y,
|
|
599
122
|
button,
|
|
600
|
-
clickCount: 1
|
|
123
|
+
clickCount: opts.clickCount ?? 1
|
|
601
124
|
});
|
|
602
125
|
}
|
|
603
126
|
async move(x, y, opts = {}) {
|
|
@@ -608,7 +131,7 @@ var XBMouseImpl = class {
|
|
|
608
131
|
const dx = x - fromX;
|
|
609
132
|
const dy = y - fromY;
|
|
610
133
|
for (let i = 1; i <= steps; i++) {
|
|
611
|
-
if (stealth) await
|
|
134
|
+
if (stealth) await sleep(rand(16, 28));
|
|
612
135
|
const t = i / steps;
|
|
613
136
|
this._x = fromX + dx * t;
|
|
614
137
|
this._y = fromY + dy * t;
|
|
@@ -642,7 +165,7 @@ var XBMouseImpl = class {
|
|
|
642
165
|
const steps = opts.steps ?? Math.max(10, Math.min(24, Math.round(Math.hypot(x - this._x, y - this._y) / 20)));
|
|
643
166
|
const fx = this._x, fy = this._y;
|
|
644
167
|
for (let i = 1; i <= steps; i++) {
|
|
645
|
-
if (stealth) await
|
|
168
|
+
if (stealth) await sleep(rand(16, 28));
|
|
646
169
|
const t = i / steps;
|
|
647
170
|
this._x = fx + (x - fx) * t;
|
|
648
171
|
this._y = fy + (y - fy) * t;
|
|
@@ -655,7 +178,7 @@ var XBMouseImpl = class {
|
|
|
655
178
|
}
|
|
656
179
|
this._x = x;
|
|
657
180
|
this._y = y;
|
|
658
|
-
await
|
|
181
|
+
await sleep(rand(60, 140));
|
|
659
182
|
await this.send("Input.dispatchMouseEvent", {
|
|
660
183
|
type: "mouseReleased",
|
|
661
184
|
x,
|
|
@@ -678,7 +201,7 @@ var XBMouseImpl = class {
|
|
|
678
201
|
await this.conn.send(method, params, this.sessionId);
|
|
679
202
|
}
|
|
680
203
|
};
|
|
681
|
-
function
|
|
204
|
+
function sleep(ms) {
|
|
682
205
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
683
206
|
}
|
|
684
207
|
|
|
@@ -708,17 +231,17 @@ var XBKeyboardImpl = class {
|
|
|
708
231
|
await this.dispatchKeyEvent(downParams);
|
|
709
232
|
if (mapping.text) {
|
|
710
233
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
711
|
-
await
|
|
234
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
712
235
|
}
|
|
713
236
|
await this.dispatchKeyEvent({
|
|
714
237
|
type: "char",
|
|
715
238
|
text: mapping.text
|
|
716
239
|
});
|
|
717
240
|
}
|
|
718
|
-
if (delay > 0) await
|
|
241
|
+
if (delay > 0) await sleep2(delay);
|
|
719
242
|
else {
|
|
720
243
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
721
|
-
await
|
|
244
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
722
245
|
}
|
|
723
246
|
}
|
|
724
247
|
const upParams = {
|
|
@@ -764,16 +287,16 @@ var XBKeyboardImpl = class {
|
|
|
764
287
|
const fixedDelay = opts.delay ?? 0;
|
|
765
288
|
for (const char of text) {
|
|
766
289
|
if (fixedDelay > 0) {
|
|
767
|
-
await
|
|
290
|
+
await sleep2(fixedDelay);
|
|
768
291
|
} else if (stealth) {
|
|
769
|
-
await
|
|
292
|
+
await sleep2(typingDelay());
|
|
770
293
|
}
|
|
771
294
|
if (stealth && char.length === 1 && Math.random() < DEFAULT_STEALTH_CONFIG.typoProbability) {
|
|
772
295
|
const wrong = NEIGHBOR_KEYS[char];
|
|
773
296
|
if (wrong && wrong !== char) {
|
|
774
297
|
await this.dispatchKeySequence(resolveKeyMapping(wrong), stealth);
|
|
775
|
-
await
|
|
776
|
-
await this.dispatchKeySequence(
|
|
298
|
+
await sleep2(rand(120, 420));
|
|
299
|
+
await this.dispatchKeySequence(KEY_MAP.Backspace, stealth);
|
|
777
300
|
}
|
|
778
301
|
}
|
|
779
302
|
await this.dispatchKeySequence(resolveKeyMapping(char), stealth);
|
|
@@ -803,7 +326,7 @@ var XBKeyboardImpl = class {
|
|
|
803
326
|
await this.dispatchKeyEvent({ type: "char", text: mapping.text });
|
|
804
327
|
}
|
|
805
328
|
if (stealth) {
|
|
806
|
-
await
|
|
329
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
807
330
|
}
|
|
808
331
|
const upParams = {
|
|
809
332
|
type: "keyUp",
|
|
@@ -842,7 +365,7 @@ var XBKeyboardImpl = class {
|
|
|
842
365
|
}
|
|
843
366
|
await this.dispatchKeyEvent(downParams);
|
|
844
367
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
845
|
-
await
|
|
368
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
846
369
|
}
|
|
847
370
|
await this.dispatchKeyEvent({
|
|
848
371
|
type: "keyUp",
|
|
@@ -866,7 +389,7 @@ var XBKeyboardImpl = class {
|
|
|
866
389
|
await this.dispatchKeyEvent({ type: "rawKeyDown", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: bits });
|
|
867
390
|
await this.dispatchKeyEvent({ type: "keyDown", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
868
391
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
869
|
-
await
|
|
392
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
870
393
|
}
|
|
871
394
|
await this.dispatchKeyEvent({ type: "keyUp", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
872
395
|
await this.dispatchKeyEvent({ type: "keyUp", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: 0 });
|
|
@@ -876,7 +399,7 @@ var XBKeyboardImpl = class {
|
|
|
876
399
|
}
|
|
877
400
|
};
|
|
878
401
|
function resolveKeyMapping(key) {
|
|
879
|
-
if (
|
|
402
|
+
if (KEY_MAP[key]) return KEY_MAP[key];
|
|
880
403
|
if (key.length === 1) {
|
|
881
404
|
const lower = key.toLowerCase();
|
|
882
405
|
if (lower >= "a" && lower <= "z") {
|
|
@@ -893,7 +416,7 @@ function resolveKeyMapping(key) {
|
|
|
893
416
|
}
|
|
894
417
|
return { key, code: key };
|
|
895
418
|
}
|
|
896
|
-
var
|
|
419
|
+
var KEY_MAP = {
|
|
897
420
|
Enter: { key: "Enter", code: "Enter", text: "\r", keyCode: 13 },
|
|
898
421
|
Tab: { key: "Tab", code: "Tab", text: " ", keyCode: 9 },
|
|
899
422
|
Escape: { key: "Escape", code: "Escape", keyCode: 27 },
|
|
@@ -962,7 +485,7 @@ var NEIGHBOR_KEYS = {
|
|
|
962
485
|
"8": "9",
|
|
963
486
|
"9": "0"
|
|
964
487
|
};
|
|
965
|
-
function
|
|
488
|
+
function sleep2(ms) {
|
|
966
489
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
967
490
|
}
|
|
968
491
|
|
|
@@ -1254,6 +777,14 @@ var XBLocatorImpl = class _XBLocatorImpl {
|
|
|
1254
777
|
await waitForActionable(this.page, this.selector, opts);
|
|
1255
778
|
await scrollIntoView(this.page, this.selector);
|
|
1256
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
|
+
`);
|
|
1257
788
|
if (process.env.XBROWSER_STEALTH !== "off" && value.length >= 40 && process.env.XBROWSER_FILL_TYPE !== "type") {
|
|
1258
789
|
try {
|
|
1259
790
|
const { pasteViaClipboard, syntheticPaste } = await import("./clipboard-BOL2GP2E.js");
|
|
@@ -2009,6 +1540,189 @@ var XBPageImpl = class _XBPageImpl {
|
|
|
2009
1540
|
await this.conn.send("Network.enable", void 0, this.sessionId);
|
|
2010
1541
|
await this.conn.send("DOM.enable", void 0, this.sessionId).catch(() => {
|
|
2011
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
|
+
});
|
|
2012
1726
|
this.setupPageEvents();
|
|
2013
1727
|
this.setupNetworkEvents();
|
|
2014
1728
|
this.setupConsoleEvents();
|
|
@@ -2040,7 +1754,7 @@ var XBPageImpl = class _XBPageImpl {
|
|
|
2040
1754
|
try {
|
|
2041
1755
|
await this.conn.send(
|
|
2042
1756
|
"Page.addScriptToEvaluateOnNewDocument",
|
|
2043
|
-
{ source: buildStealthInitScript() },
|
|
1757
|
+
{ source: buildStealthInitScript({ ...DEFAULT_STEALTH_CONFIG, ...this._contextImpl.stealthConfig ?? {} }) },
|
|
2044
1758
|
this.sessionId
|
|
2045
1759
|
);
|
|
2046
1760
|
} catch {
|
|
@@ -2449,7 +2163,9 @@ Last error: ${lastError.message}` : "";
|
|
|
2449
2163
|
await this.locator(selector).click(opts);
|
|
2450
2164
|
}
|
|
2451
2165
|
async dblclick(selector, opts = {}) {
|
|
2452
|
-
|
|
2166
|
+
const locator = this.locator(selector);
|
|
2167
|
+
await locator.click({ ...opts, clickCount: 1 });
|
|
2168
|
+
await locator.click({ ...opts, clickCount: 2 });
|
|
2453
2169
|
}
|
|
2454
2170
|
async fill(selector, value, opts = {}) {
|
|
2455
2171
|
await this.locator(selector).fill(value, opts);
|
|
@@ -2566,6 +2282,26 @@ Last error: ${lastError.message}` : "";
|
|
|
2566
2282
|
);
|
|
2567
2283
|
this._viewportSize = size;
|
|
2568
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
|
+
}
|
|
2569
2305
|
// ── Scripts ─────────────────────────────────────────────────
|
|
2570
2306
|
async addInitScript(script) {
|
|
2571
2307
|
await this.conn.send(
|
|
@@ -2789,6 +2525,12 @@ Last error: ${lastError.message}` : "";
|
|
|
2789
2525
|
async _cdpSend(method, params) {
|
|
2790
2526
|
return this.conn.send(method, params, this.sessionId);
|
|
2791
2527
|
}
|
|
2528
|
+
/** sup-s11: beforeunload 自动应答语义——'accept'(默认,离开页面,与录制
|
|
2529
|
+
* 意图一致)或 'dismiss'(取消导航留守原页,尽力而为:此构建上 CDP
|
|
2530
|
+
* accept:false 对浏览器侧导航的取消语义不稳定,不保证)。 */
|
|
2531
|
+
setBeforeUnloadBehavior(mode) {
|
|
2532
|
+
this._beforeUnloadAccept = mode === "accept";
|
|
2533
|
+
}
|
|
2792
2534
|
/**
|
|
2793
2535
|
* 开启/关闭原生文件选择框拦截(CDP stateful 开关)。
|
|
2794
2536
|
*
|
|
@@ -2847,8 +2589,9 @@ Last error: ${lastError.message}` : "";
|
|
|
2847
2589
|
}
|
|
2848
2590
|
};
|
|
2849
2591
|
this._emit("dialog", dialog);
|
|
2592
|
+
const autoAccept = p.type === "beforeunload" ? this._beforeUnloadAccept : false;
|
|
2850
2593
|
setTimeout(() => {
|
|
2851
|
-
this.conn.send("Page.handleJavaScriptDialog", { accept:
|
|
2594
|
+
this.conn.send("Page.handleJavaScriptDialog", { accept: autoAccept }, this.sessionId).catch(() => {
|
|
2852
2595
|
});
|
|
2853
2596
|
}, 0);
|
|
2854
2597
|
})
|
|
@@ -2991,6 +2734,7 @@ Last error: ${lastError.message}` : "";
|
|
|
2991
2734
|
_networkRequests = /* @__PURE__ */ new Map();
|
|
2992
2735
|
_routeHandlers = [];
|
|
2993
2736
|
_interceptionEnabled = false;
|
|
2737
|
+
_beforeUnloadAccept = true;
|
|
2994
2738
|
/** Store network data — called by browser.ts installNetworkCapture or internal event handlers */
|
|
2995
2739
|
_storeNetworkRequest(requestId, data) {
|
|
2996
2740
|
this._networkRequests.set(requestId, { requestId, ...data });
|
|
@@ -3102,7 +2846,10 @@ Last error: ${lastError.message}` : "";
|
|
|
3102
2846
|
if (!this._interceptionEnabled) {
|
|
3103
2847
|
this._interceptionEnabled = true;
|
|
3104
2848
|
await this.conn.send("Fetch.enable", {
|
|
3105
|
-
patterns: [{ urlPattern: "*", requestStage: "Request" }]
|
|
2849
|
+
patterns: [{ urlPattern: "*", requestStage: "Request" }],
|
|
2850
|
+
// sup-s9: 保留认证自动响应(Fetch.enable 为替换语义,不带此参数
|
|
2851
|
+
// 会顶掉 _init 的 auth 配置)
|
|
2852
|
+
handleAuthRequests: true
|
|
3106
2853
|
}, this.sessionId);
|
|
3107
2854
|
this._subscriptions.push(
|
|
3108
2855
|
this.conn.subscribe("Fetch.requestPaused", this.sessionId, (params) => {
|
|
@@ -3155,6 +2902,36 @@ Last error: ${lastError.message}` : "";
|
|
|
3155
2902
|
});
|
|
3156
2903
|
}
|
|
3157
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
|
+
}
|
|
3158
2935
|
async setInputFiles(selector, files) {
|
|
3159
2936
|
const fileArr = Array.isArray(files) ? files : [files];
|
|
3160
2937
|
const fileList = fileArr.map((f) => ({
|
|
@@ -3297,6 +3074,18 @@ var XBContextImpl = class {
|
|
|
3297
3074
|
this.options = opts;
|
|
3298
3075
|
this.setupAutoAttach();
|
|
3299
3076
|
}
|
|
3077
|
+
/** S194: 任务 tab 的 stealth 配置(UA-CH 档案等)经 context 传给 page 层 */
|
|
3078
|
+
get stealthConfig() {
|
|
3079
|
+
return this.options.stealthConfig;
|
|
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
|
+
}
|
|
3300
3089
|
async newPage() {
|
|
3301
3090
|
if (this.closed) throw new Error("Context is closed");
|
|
3302
3091
|
const { targetId } = await this._browser._createTarget(this.contextId);
|
|
@@ -3463,20 +3252,8 @@ var XBContextImpl = class {
|
|
|
3463
3252
|
|
|
3464
3253
|
// src/cdp-driver/browser.ts
|
|
3465
3254
|
var XBBrowserImpl = class {
|
|
3466
|
-
conn
|
|
3467
|
-
|
|
3468
|
-
_contexts = /* @__PURE__ */ new Map();
|
|
3469
|
-
_disconnected = false;
|
|
3470
|
-
childProcess = null;
|
|
3471
|
-
tmpDir;
|
|
3472
|
-
_exitHandler = null;
|
|
3473
|
-
/**
|
|
3474
|
-
* Original CDP endpoint (HTTP or ws URL) used to construct this browser.
|
|
3475
|
-
* Used by discoverContexts() as a fallback to HTTP /json/list when
|
|
3476
|
-
* Target.getTargets doesn't return page-type targets (e.g. cdp-tunnel proxy).
|
|
3477
|
-
*/
|
|
3478
|
-
cdpEndpoint;
|
|
3479
|
-
constructor(conn, childProcess, tmpDir, cdpEndpoint) {
|
|
3255
|
+
constructor(conn, childProcess, tmpDir, cdpEndpoint, launchOpts) {
|
|
3256
|
+
this.launchOpts = launchOpts;
|
|
3480
3257
|
this.conn = conn;
|
|
3481
3258
|
this.childProcess = childProcess ?? null;
|
|
3482
3259
|
this.tmpDir = tmpDir;
|
|
@@ -3504,6 +3281,20 @@ var XBBrowserImpl = class {
|
|
|
3504
3281
|
process.on("exit", this._exitHandler);
|
|
3505
3282
|
}
|
|
3506
3283
|
}
|
|
3284
|
+
launchOpts;
|
|
3285
|
+
conn;
|
|
3286
|
+
_emitter = new EventEmitter3();
|
|
3287
|
+
_contexts = /* @__PURE__ */ new Map();
|
|
3288
|
+
_disconnected = false;
|
|
3289
|
+
childProcess = null;
|
|
3290
|
+
tmpDir;
|
|
3291
|
+
_exitHandler = null;
|
|
3292
|
+
/**
|
|
3293
|
+
* Original CDP endpoint (HTTP or ws URL) used to construct this browser.
|
|
3294
|
+
* Used by discoverContexts() as a fallback to HTTP /json/list when
|
|
3295
|
+
* Target.getTargets doesn't return page-type targets (e.g. cdp-tunnel proxy).
|
|
3296
|
+
*/
|
|
3297
|
+
cdpEndpoint;
|
|
3507
3298
|
get disconnected() {
|
|
3508
3299
|
return this._disconnected;
|
|
3509
3300
|
}
|
|
@@ -3524,13 +3315,16 @@ var XBBrowserImpl = class {
|
|
|
3524
3315
|
this._exitHandler = null;
|
|
3525
3316
|
}
|
|
3526
3317
|
if (this.childProcess) {
|
|
3527
|
-
const { killChrome: killChrome2 } = await import("./launcher-
|
|
3318
|
+
const { killChrome: killChrome2 } = await import("./launcher-IK2FKW6T.js");
|
|
3528
3319
|
await killChrome2(this.childProcess, this.tmpDir);
|
|
3529
3320
|
}
|
|
3530
3321
|
await this.conn.close();
|
|
3531
3322
|
this._emitter.emit("disconnected");
|
|
3532
3323
|
}
|
|
3533
3324
|
async newContext(opts = {}) {
|
|
3325
|
+
if (this.launchOpts?.stealthConfig && !opts.stealthConfig) {
|
|
3326
|
+
opts = { ...opts, stealthConfig: this.launchOpts.stealthConfig };
|
|
3327
|
+
}
|
|
3534
3328
|
if (this._disconnected) {
|
|
3535
3329
|
throw new Error("Browser is disconnected");
|
|
3536
3330
|
}
|
|
@@ -3547,6 +3341,38 @@ var XBBrowserImpl = class {
|
|
|
3547
3341
|
} catch {
|
|
3548
3342
|
}
|
|
3549
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
|
+
}
|
|
3550
3376
|
context.on("page", (page) => {
|
|
3551
3377
|
this._emitter.emit("page", page);
|
|
3552
3378
|
});
|
|
@@ -3659,7 +3485,7 @@ var XBBrowserImpl = class {
|
|
|
3659
3485
|
if (pageTargets.length === 0 && httpFallbackUrl) {
|
|
3660
3486
|
console.log(`[discoverContexts] Target.getTargets returned ${targetInfos.length} targets (0 page type). Falling back to HTTP /json/list at ${httpFallbackUrl}`);
|
|
3661
3487
|
try {
|
|
3662
|
-
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-
|
|
3488
|
+
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-IK2FKW6T.js");
|
|
3663
3489
|
const httpPages = await getCDPTargets2(httpFallbackUrl);
|
|
3664
3490
|
console.log(`[discoverContexts] HTTP /json/list returned ${httpPages.length} pages`);
|
|
3665
3491
|
for (const p of httpPages) {
|
|
@@ -4083,15 +3909,27 @@ async function launch(options = {}) {
|
|
|
4083
3909
|
}
|
|
4084
3910
|
const conn = new CDPConnection(wsEndpoint);
|
|
4085
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
|
+
}
|
|
4086
3927
|
const httpEndpoint = options.cdpEndpoint && !options.cdpEndpoint.startsWith("ws") ? options.cdpEndpoint : void 0;
|
|
4087
|
-
const browser = new XBBrowserImpl(conn, childProcess, tmpDir, httpEndpoint);
|
|
3928
|
+
const browser = new XBBrowserImpl(conn, childProcess, tmpDir, httpEndpoint, stealthOpts);
|
|
4088
3929
|
return { browser, wsEndpoint };
|
|
4089
3930
|
}
|
|
4090
3931
|
|
|
4091
3932
|
export {
|
|
4092
|
-
rand,
|
|
4093
|
-
sleep,
|
|
4094
|
-
wheelDelta,
|
|
4095
3933
|
XBMouseImpl,
|
|
4096
3934
|
XBKeyboardImpl,
|
|
4097
3935
|
waitForActionable,
|