@xbrowser/cli 1.14.0 → 1.16.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/dist/{browser-KJWBHGHX.js → browser-3KTEVTMU.js} +2 -2
- package/dist/{browser-5A6AL62M.js → browser-AOVQTGJ7.js} +2 -2
- package/dist/{browser-DI6UQN6Q.js → browser-KT4FOWBO.js} +1 -1
- package/dist/{cdp-driver-QXTXJZH7.js → cdp-driver-ALDP2CZT.js} +248 -49
- package/dist/{cdp-driver-4SFS6GNY.js → cdp-driver-DKNLIA6B.js} +1 -1
- package/dist/{cdp-driver-AHKUT57K.js → cdp-driver-OC37OT4B.js} +1 -1
- package/dist/{chunk-BTFKJD7Z.js → chunk-5EYOEB4R.js} +277 -65
- package/dist/{chunk-B753M33E.js → chunk-7V3B7VPX.js} +9 -7
- package/dist/{chunk-PYQGDBAF.js → chunk-A5HJ6IRE.js} +269 -59
- package/dist/{chunk-ZD4OSYOX.js → chunk-GWQ5NTVE.js} +9 -7
- package/dist/{chunk-UPAWITVM.js → chunk-LTBNQERK.js} +269 -59
- package/dist/cli.js +86 -32
- package/dist/clipboard-BOL2GP2E.js +58 -0
- package/dist/clipboard-XRP54ENE.js +58 -0
- package/dist/daemon-main.js +44 -22
- package/dist/index.d.ts +4 -0
- package/dist/index.js +106 -51
- package/dist/{session-replayer-I3PJFO3H.js → session-replayer-MJH5W7BB.js} +1 -1
- package/package.json +1 -1
- package/dist/{recovery-Z3RDZENA.js → recovery-MDWAVXE4.js} +4 -4
- package/dist/{recovery-FTZGV6VY.js → recovery-NXC35EQN.js} +4 -4
|
@@ -27,7 +27,7 @@ var DEFAULT_STEALTH_CONFIG = {
|
|
|
27
27
|
bezierCurvature: [0.35, 0.6],
|
|
28
28
|
noiseAmplitude: 5.5,
|
|
29
29
|
overshootRange: [6, 14],
|
|
30
|
-
aimPause: [
|
|
30
|
+
aimPause: [80, 280],
|
|
31
31
|
pressDuration: [60, 140],
|
|
32
32
|
releaseDrift: [0.8, 2.5],
|
|
33
33
|
landingOffsetSmall: [0.3, 2.5],
|
|
@@ -48,6 +48,9 @@ var DEFAULT_STEALTH_CONFIG = {
|
|
|
48
48
|
function rand(min, max) {
|
|
49
49
|
return min + Math.random() * (max - min);
|
|
50
50
|
}
|
|
51
|
+
function sleep(ms) {
|
|
52
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
+
}
|
|
51
54
|
function cosineEase(t) {
|
|
52
55
|
return 0.5 - 0.5 * Math.cos(Math.PI * t);
|
|
53
56
|
}
|
|
@@ -95,6 +98,18 @@ function landingOffset(width, height, config = DEFAULT_STEALTH_CONFIG) {
|
|
|
95
98
|
const dy = rand(...range) * (Math.random() < 0.5 ? -1 : 1);
|
|
96
99
|
return { dx, dy };
|
|
97
100
|
}
|
|
101
|
+
function typingDelay(config = DEFAULT_STEALTH_CONFIG) {
|
|
102
|
+
const roll = Math.random();
|
|
103
|
+
const r = config.typingRhythm;
|
|
104
|
+
if (roll < r.pauseProb) return rand(...r.pauseRange);
|
|
105
|
+
if (roll < r.pauseProb + r.fastProb) return rand(...r.fastRange);
|
|
106
|
+
return rand(...r.normalRange);
|
|
107
|
+
}
|
|
108
|
+
function wheelDelta(step, config = DEFAULT_STEALTH_CONFIG) {
|
|
109
|
+
return Math.round(
|
|
110
|
+
config.wheelPeak * Math.exp(-step * config.wheelDecayRate) * rand(0.85, 1.15)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
98
113
|
var KEY_MAP = {};
|
|
99
114
|
for (let i = 97; i <= 122; i++) {
|
|
100
115
|
const ch = String.fromCharCode(i);
|
|
@@ -118,6 +133,7 @@ Object.assign(KEY_MAP, {
|
|
|
118
133
|
function buildStealthInitScript() {
|
|
119
134
|
return [
|
|
120
135
|
"(function(){",
|
|
136
|
+
' window.__xbStealthVer="57";',
|
|
121
137
|
// 1. AEL event proxy
|
|
122
138
|
" var o=EventTarget.prototype.addEventListener;",
|
|
123
139
|
" var fc=new InputDeviceCapabilities({firesTouchEvents:false});",
|
|
@@ -280,6 +296,70 @@ function buildStealthInitScript() {
|
|
|
280
296
|
' var _pto=Object.getOwnPropertyDescriptor(Performance.prototype,"timeOrigin");',
|
|
281
297
|
' if(_pto&&_pto.get){Object.defineProperty(performance,"timeOrigin",{get:function(){return _pto.get.call(performance);},configurable:true});}',
|
|
282
298
|
" }catch(e){}",
|
|
299
|
+
// 3f. getCoalescedEvents 合成(d47):真实鼠标 125Hz 采样被浏览器按帧合并,
|
|
300
|
+
// 快速移动时 pointermove.getCoalescedEvents() 返回 2~6 个事件(群内
|
|
301
|
+
// ≈8ms);CDP Input 逐事件派发不走合并管线,coalesced>1 恒为 0(结构性
|
|
302
|
+
// 暴露,间隔模拟救不了——实测 Chrome 帧对齐时 CDP 连发事件被直接丢弃
|
|
303
|
+
// 而非合并)。按 125Hz 物理插值合成 coalesced 群:期望样本数 = dt/8ms-1,
|
|
304
|
+
// 合成事件用真 PointerEvent 构造 + 实例级 isTrusted/timeStamp 遮蔽。
|
|
305
|
+
" try{",
|
|
306
|
+
" if(window.PointerEvent&&PointerEvent.prototype.getCoalescedEvents){",
|
|
307
|
+
" var _gce=PointerEvent.prototype.getCoalescedEvents;",
|
|
308
|
+
" var _lm=null;",
|
|
309
|
+
" var _gceH=function(){",
|
|
310
|
+
" var list=_gce.call(this);",
|
|
311
|
+
' if(this.type!=="pointermove"||!this.isTrusted)return list;',
|
|
312
|
+
" var cur={x:this.clientX,y:this.clientY,ts:this.timeStamp};",
|
|
313
|
+
" var out=null;",
|
|
314
|
+
" if((!list||list.length<2)&&_lm){",
|
|
315
|
+
" var dt=cur.ts-_lm.ts,dx=cur.x-_lm.x,dy=cur.y-_lm.y;",
|
|
316
|
+
// dt 长(帧丢弃后)不代表群覆盖整个 dt —— 真实 coalesced 群只覆盖
|
|
317
|
+
// 最后一帧窗口(≤16.7ms,群内 ≈8ms=125Hz)。合成群从自身往回推 8ms
|
|
318
|
+
// 链,位移取末端占比(span/dt,dt 远大于 span 时位移趋零=丢弃后实况)。
|
|
319
|
+
" var expN=Math.floor(dt/8)-1;",
|
|
320
|
+
// dt<12ms(不足一帧+采样周期)时真实浏览器不会产生合并群 ——
|
|
321
|
+
// 单采样帧 coalesced=1,强行合成会出现 ~2ms 的超物理群内间隔。
|
|
322
|
+
" if(expN>0&&dt>=12&&Math.random()>0.15){",
|
|
323
|
+
" var n=Math.min(4,expN+(Math.random()<0.3?1:0));",
|
|
324
|
+
" var span=Math.min(dt,n*8.3);",
|
|
325
|
+
" var frac=Math.min(1,span/Math.max(dt,1));",
|
|
326
|
+
" out=[];",
|
|
327
|
+
" for(var i=1;i<=n;i++){",
|
|
328
|
+
// k=距自身的步数(含自身共 n+1 个事件,相邻恒 ≈8.3ms=125Hz 周期)
|
|
329
|
+
" var k=n+1-i;",
|
|
330
|
+
' var ev=new PointerEvent("pointermove",{',
|
|
331
|
+
' pointerId:this.pointerId,pointerType:"mouse",isPrimary:this.isPrimary,',
|
|
332
|
+
" clientX:cur.x-dx*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
333
|
+
" clientY:cur.y-dy*frac*(k/(n+1))+(Math.random()-0.5)*1.5,",
|
|
334
|
+
" screenX:this.screenX,screenY:this.screenY,",
|
|
335
|
+
" buttons:this.buttons,button:this.button,",
|
|
336
|
+
" bubbles:true,cancelable:true,composed:true,",
|
|
337
|
+
" width:this.width,height:this.height,pressure:this.pressure,",
|
|
338
|
+
" tiltX:this.tiltX,tiltY:this.tiltY,twist:this.twist});",
|
|
339
|
+
" var tsV=cur.ts-k*8.3-Math.random()*1.2;",
|
|
340
|
+
// isTrusted/timeStamp 是实例不可配置属性(defineProperty 抛
|
|
341
|
+
// "Cannot redefine"),改 Proxy 包装:getPrototypeOf/ownKeys 透传,
|
|
342
|
+
// instanceof 与属性枚举行为与真事件一致。IIFE 捕获本次循环的 tsV
|
|
343
|
+
// 快照 —— var 提升会让所有 Proxy 闭包共享最后一次赋值(实测四个
|
|
344
|
+
// 合成事件同时间戳、群内间隔塌到 ~2ms)。
|
|
345
|
+
" out.push((function(e2,t2){return new Proxy(e2,{get:function(t,p){",
|
|
346
|
+
' if(p==="isTrusted")return true;',
|
|
347
|
+
' if(p==="timeStamp")return t2;',
|
|
348
|
+
' var v=Reflect.get(t,p);return typeof v==="function"?v.bind(t):v;',
|
|
349
|
+
" }});})(ev,tsV));",
|
|
350
|
+
" }",
|
|
351
|
+
" out.push(this);",
|
|
352
|
+
" }",
|
|
353
|
+
" }",
|
|
354
|
+
" _lm=cur;",
|
|
355
|
+
" return out||list;",
|
|
356
|
+
" };",
|
|
357
|
+
" PointerEvent.prototype.getCoalescedEvents=_gceH;",
|
|
358
|
+
// name 反查伪装:var _gceH=fn 的具名推断会暴露 hook(原生 name 是
|
|
359
|
+
// "getCoalescedEvents")——toString 白名单管不到 name 属性。
|
|
360
|
+
' try{Object.defineProperty(_gceH,"name",{value:"getCoalescedEvents"});}catch(e){}',
|
|
361
|
+
" }",
|
|
362
|
+
" }catch(e){}",
|
|
283
363
|
// 3d. Chrome object depth (d24): automation fakes usually only set
|
|
284
364
|
// window.chrome = {}; deep checks hit app.run/runtime/csi/loadTimes.
|
|
285
365
|
" try{",
|
|
@@ -314,6 +394,7 @@ function buildStealthInitScript() {
|
|
|
314
394
|
' if(this===HTMLCanvasElement.prototype.toDataURL)return"function toDataURL() { [native code] }";',
|
|
315
395
|
' if(this===AnalyserNode.prototype.getFloatFrequencyData)return"function getFloatFrequencyData() { [native code] }";',
|
|
316
396
|
' if(this===AudioBuffer.prototype.getChannelData)return"function getChannelData() { [native code] }";',
|
|
397
|
+
' if(this===_gceH)return"function getCoalescedEvents() { [native code] }";',
|
|
317
398
|
" return _ts.call(this);",
|
|
318
399
|
" };",
|
|
319
400
|
// 4. onclick prototype hijack (dual-stream consistency)
|
|
@@ -374,26 +455,26 @@ var XBMouseImpl = class {
|
|
|
374
455
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: p.x, y: p.y, button: this._button });
|
|
375
456
|
this._x = p.x;
|
|
376
457
|
this._y = p.y;
|
|
377
|
-
await
|
|
458
|
+
await sleep2(p.delay);
|
|
378
459
|
}
|
|
379
460
|
this._x = tx;
|
|
380
461
|
this._y = ty;
|
|
381
462
|
if (_truncated) {
|
|
382
463
|
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: tx, y: ty, button: this._button });
|
|
383
464
|
}
|
|
384
|
-
await
|
|
465
|
+
await sleep2(rand(...DEFAULT_STEALTH_CONFIG.aimPause));
|
|
385
466
|
} else {
|
|
386
467
|
await this.move(tx, ty);
|
|
387
468
|
}
|
|
388
469
|
await this.down({ button });
|
|
389
|
-
await
|
|
470
|
+
await sleep2(stealth ? rand(...DEFAULT_STEALTH_CONFIG.pressDuration) : opts.delay ?? 0);
|
|
390
471
|
const rx = stealth ? this._x + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._x;
|
|
391
472
|
const ry = stealth ? this._y + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._y;
|
|
392
473
|
this._x = rx;
|
|
393
474
|
this._y = ry;
|
|
394
475
|
await this.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: rx, y: ry, button, clickCount: opts.clickCount ?? 1 });
|
|
395
476
|
for (let i = 1; i < (opts.clickCount ?? 1); i++) {
|
|
396
|
-
if (opts.delay) await
|
|
477
|
+
if (opts.delay) await sleep2(opts.delay);
|
|
397
478
|
await this.down({ button });
|
|
398
479
|
await this.up({ button });
|
|
399
480
|
}
|
|
@@ -424,12 +505,14 @@ var XBMouseImpl = class {
|
|
|
424
505
|
});
|
|
425
506
|
}
|
|
426
507
|
async move(x, y, opts = {}) {
|
|
508
|
+
const stealth = opts.stealth ?? process.env.XBROWSER_STEALTH !== "off";
|
|
427
509
|
const steps = Math.max(1, opts.steps ?? 1);
|
|
428
510
|
const fromX = this._x;
|
|
429
511
|
const fromY = this._y;
|
|
430
512
|
const dx = x - fromX;
|
|
431
513
|
const dy = y - fromY;
|
|
432
514
|
for (let i = 1; i <= steps; i++) {
|
|
515
|
+
if (stealth) await sleep2(rand(16, 28));
|
|
433
516
|
const t = i / steps;
|
|
434
517
|
this._x = fromX + dx * t;
|
|
435
518
|
this._y = fromY + dy * t;
|
|
@@ -456,7 +539,7 @@ var XBMouseImpl = class {
|
|
|
456
539
|
await this.conn.send(method, params, this.sessionId);
|
|
457
540
|
}
|
|
458
541
|
};
|
|
459
|
-
function
|
|
542
|
+
function sleep2(ms) {
|
|
460
543
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
461
544
|
}
|
|
462
545
|
|
|
@@ -486,17 +569,17 @@ var XBKeyboardImpl = class {
|
|
|
486
569
|
await this.dispatchKeyEvent(downParams);
|
|
487
570
|
if (mapping.text) {
|
|
488
571
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
489
|
-
await
|
|
572
|
+
await sleep3(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
490
573
|
}
|
|
491
574
|
await this.dispatchKeyEvent({
|
|
492
575
|
type: "char",
|
|
493
576
|
text: mapping.text
|
|
494
577
|
});
|
|
495
578
|
}
|
|
496
|
-
if (delay > 0) await
|
|
579
|
+
if (delay > 0) await sleep3(delay);
|
|
497
580
|
else {
|
|
498
581
|
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
499
|
-
await
|
|
582
|
+
await sleep3(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
500
583
|
}
|
|
501
584
|
}
|
|
502
585
|
const upParams = {
|
|
@@ -542,45 +625,56 @@ var XBKeyboardImpl = class {
|
|
|
542
625
|
const fixedDelay = opts.delay ?? 0;
|
|
543
626
|
for (const char of text) {
|
|
544
627
|
if (fixedDelay > 0) {
|
|
545
|
-
await
|
|
628
|
+
await sleep3(fixedDelay);
|
|
546
629
|
} else if (stealth) {
|
|
547
|
-
|
|
548
|
-
const cfg = DEFAULT_STEALTH_CONFIG.typingRhythm;
|
|
549
|
-
if (roll < cfg.pauseProb) {
|
|
550
|
-
await sleep2(rand(cfg.pauseRange[0], cfg.pauseRange[1]));
|
|
551
|
-
} else if (roll < cfg.pauseProb + cfg.fastProb) {
|
|
552
|
-
await sleep2(rand(cfg.fastRange[0], cfg.fastRange[1]));
|
|
553
|
-
} else {
|
|
554
|
-
await sleep2(rand(cfg.normalRange[0], cfg.normalRange[1]));
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
const mapping = resolveKeyMapping(char);
|
|
558
|
-
const downParams = {
|
|
559
|
-
type: "rawKeyDown",
|
|
560
|
-
key: mapping.key,
|
|
561
|
-
code: mapping.code
|
|
562
|
-
};
|
|
563
|
-
if (mapping.text) {
|
|
564
|
-
downParams.text = mapping.text;
|
|
565
|
-
downParams.unmodifiedText = mapping.text;
|
|
566
|
-
}
|
|
567
|
-
if (mapping.keyCode) {
|
|
568
|
-
downParams.windowsVirtualKeyCode = mapping.keyCode;
|
|
630
|
+
await sleep3(typingDelay());
|
|
569
631
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
632
|
+
if (stealth && char.length === 1 && Math.random() < DEFAULT_STEALTH_CONFIG.typoProbability) {
|
|
633
|
+
const wrong = NEIGHBOR_KEYS[char];
|
|
634
|
+
if (wrong && wrong !== char) {
|
|
635
|
+
await this.dispatchKeySequence(resolveKeyMapping(wrong), stealth);
|
|
636
|
+
await sleep3(rand(120, 420));
|
|
637
|
+
await this.dispatchKeySequence(KEY_MAP2.Backspace, stealth);
|
|
638
|
+
}
|
|
576
639
|
}
|
|
577
|
-
await this.
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
640
|
+
await this.dispatchKeySequence(resolveKeyMapping(char), stealth);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Single-key event sequence: rawKeyDown → (char) → keyUp.
|
|
645
|
+
* Shared by press() and type() — two separate implementations drifted
|
|
646
|
+
* apart once already (S60: type() lost the keyPressDuration that press()
|
|
647
|
+
* had; d50 caught it as 33/33 keys with down→up of 2ms).
|
|
648
|
+
*/
|
|
649
|
+
async dispatchKeySequence(mapping, stealth) {
|
|
650
|
+
const downParams = {
|
|
651
|
+
type: "rawKeyDown",
|
|
652
|
+
key: mapping.key,
|
|
653
|
+
code: mapping.code
|
|
654
|
+
};
|
|
655
|
+
if (mapping.text) {
|
|
656
|
+
downParams.text = mapping.text;
|
|
657
|
+
downParams.unmodifiedText = mapping.text;
|
|
658
|
+
}
|
|
659
|
+
if (mapping.keyCode) {
|
|
660
|
+
downParams.windowsVirtualKeyCode = mapping.keyCode;
|
|
661
|
+
}
|
|
662
|
+
await this.dispatchKeyEvent(downParams);
|
|
663
|
+
if (mapping.text) {
|
|
664
|
+
await this.dispatchKeyEvent({ type: "char", text: mapping.text });
|
|
583
665
|
}
|
|
666
|
+
if (stealth) {
|
|
667
|
+
await sleep3(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
668
|
+
}
|
|
669
|
+
const upParams = {
|
|
670
|
+
type: "keyUp",
|
|
671
|
+
key: mapping.key,
|
|
672
|
+
code: mapping.code
|
|
673
|
+
};
|
|
674
|
+
if (mapping.keyCode) {
|
|
675
|
+
upParams.windowsVirtualKeyCode = mapping.keyCode;
|
|
676
|
+
}
|
|
677
|
+
await this.dispatchKeyEvent(upParams);
|
|
584
678
|
}
|
|
585
679
|
async insertText(text) {
|
|
586
680
|
await this.conn.send(
|
|
@@ -589,6 +683,55 @@ var XBKeyboardImpl = class {
|
|
|
589
683
|
this.sessionId
|
|
590
684
|
);
|
|
591
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Navigation key press using CDP type 'keyDown' (NOT rawKeyDown).
|
|
688
|
+
* rawKeyDown skips browser default actions — select option navigation,
|
|
689
|
+
* arrow-key scrolling etc. never fire under it (d53: ArrowDown on a
|
|
690
|
+
* focused <select> left the value unchanged). keyDown carries the
|
|
691
|
+
* default action.
|
|
692
|
+
*/
|
|
693
|
+
async pressNav(key) {
|
|
694
|
+
const mapping = resolveKeyMapping(key);
|
|
695
|
+
const downParams = {
|
|
696
|
+
type: "keyDown",
|
|
697
|
+
key: mapping.key,
|
|
698
|
+
code: mapping.code
|
|
699
|
+
};
|
|
700
|
+
if (mapping.keyCode) {
|
|
701
|
+
downParams.windowsVirtualKeyCode = mapping.keyCode;
|
|
702
|
+
downParams.nativeVirtualKeyCode = mapping.keyCode;
|
|
703
|
+
}
|
|
704
|
+
await this.dispatchKeyEvent(downParams);
|
|
705
|
+
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
706
|
+
await sleep3(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
707
|
+
}
|
|
708
|
+
await this.dispatchKeyEvent({
|
|
709
|
+
type: "keyUp",
|
|
710
|
+
key: mapping.key,
|
|
711
|
+
code: mapping.code,
|
|
712
|
+
...mapping.keyCode ? { windowsVirtualKeyCode: mapping.keyCode } : {}
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Shortcut combo press (modifier+key) with explicit per-event modifiers
|
|
717
|
+
* bitmask — plain down(mod)+press(key) inserts the raw character because
|
|
718
|
+
* CDP modifiers are per-event fields, not session state (d56: Meta,v
|
|
719
|
+
* typed a literal 'v'). keyDown type carries the default action so the
|
|
720
|
+
* browser's shortcut dispatcher sees the combo (e.g. native paste).
|
|
721
|
+
*/
|
|
722
|
+
async pressCombo(key, modifier) {
|
|
723
|
+
const MODBIT = { Alt: 1, Control: 2, Meta: 4, Shift: 8 };
|
|
724
|
+
const m = resolveKeyMapping(modifier);
|
|
725
|
+
const k = resolveKeyMapping(key);
|
|
726
|
+
const bits = MODBIT[modifier] ?? 0;
|
|
727
|
+
await this.dispatchKeyEvent({ type: "rawKeyDown", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: bits });
|
|
728
|
+
await this.dispatchKeyEvent({ type: "keyDown", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
729
|
+
if (process.env.XBROWSER_STEALTH !== "off") {
|
|
730
|
+
await sleep3(rand(...DEFAULT_STEALTH_CONFIG.keyPressDuration));
|
|
731
|
+
}
|
|
732
|
+
await this.dispatchKeyEvent({ type: "keyUp", key: k.key, code: k.code, ...k.keyCode ? { windowsVirtualKeyCode: k.keyCode } : {}, modifiers: bits });
|
|
733
|
+
await this.dispatchKeyEvent({ type: "keyUp", key: m.key, code: m.code, ...m.keyCode ? { windowsVirtualKeyCode: m.keyCode } : {}, modifiers: 0 });
|
|
734
|
+
}
|
|
592
735
|
async dispatchKeyEvent(params) {
|
|
593
736
|
await this.conn.send("Input.dispatchKeyEvent", params, this.sessionId);
|
|
594
737
|
}
|
|
@@ -643,7 +786,44 @@ var KEY_MAP2 = {
|
|
|
643
786
|
F11: { key: "F11", code: "F11", keyCode: 122 },
|
|
644
787
|
F12: { key: "F12", code: "F12", keyCode: 123 }
|
|
645
788
|
};
|
|
646
|
-
|
|
789
|
+
var NEIGHBOR_KEYS = {
|
|
790
|
+
a: "s",
|
|
791
|
+
b: "v",
|
|
792
|
+
c: "x",
|
|
793
|
+
d: "f",
|
|
794
|
+
e: "r",
|
|
795
|
+
f: "g",
|
|
796
|
+
g: "h",
|
|
797
|
+
h: "j",
|
|
798
|
+
i: "o",
|
|
799
|
+
j: "k",
|
|
800
|
+
k: "l",
|
|
801
|
+
l: "k",
|
|
802
|
+
m: "n",
|
|
803
|
+
n: "m",
|
|
804
|
+
o: "p",
|
|
805
|
+
p: "o",
|
|
806
|
+
q: "w",
|
|
807
|
+
r: "t",
|
|
808
|
+
s: "d",
|
|
809
|
+
t: "y",
|
|
810
|
+
u: "i",
|
|
811
|
+
v: "b",
|
|
812
|
+
w: "e",
|
|
813
|
+
x: "c",
|
|
814
|
+
y: "u",
|
|
815
|
+
z: "x",
|
|
816
|
+
"1": "2",
|
|
817
|
+
"2": "3",
|
|
818
|
+
"3": "4",
|
|
819
|
+
"4": "5",
|
|
820
|
+
"5": "6",
|
|
821
|
+
"6": "7",
|
|
822
|
+
"7": "8",
|
|
823
|
+
"8": "9",
|
|
824
|
+
"9": "0"
|
|
825
|
+
};
|
|
826
|
+
function sleep3(ms) {
|
|
647
827
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
648
828
|
}
|
|
649
829
|
|
|
@@ -833,6 +1013,18 @@ var XBLocatorImpl = class _XBLocatorImpl {
|
|
|
833
1013
|
await waitForActionable(this.page, this.selector, opts);
|
|
834
1014
|
await scrollIntoView(this.page, this.selector);
|
|
835
1015
|
await this.click({ ...opts });
|
|
1016
|
+
if (process.env.XBROWSER_STEALTH !== "off" && value.length >= 40 && process.env.XBROWSER_FILL_TYPE !== "type") {
|
|
1017
|
+
try {
|
|
1018
|
+
const { pasteViaClipboard, syntheticPaste } = await import("./clipboard-BOL2GP2E.js");
|
|
1019
|
+
await pasteViaClipboard(this.page, value);
|
|
1020
|
+
const got = await this.page.evaluate(
|
|
1021
|
+
`(function(){ const el = ${this._q(this.selector)}; return el ? (el.value || '') : ''; })()`
|
|
1022
|
+
);
|
|
1023
|
+
if (got === value) return;
|
|
1024
|
+
if (await syntheticPaste(this.page, this._q(this.selector), value)) return;
|
|
1025
|
+
} catch {
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
836
1028
|
await this.page.keyboard.type(value, { stealth: true });
|
|
837
1029
|
return;
|
|
838
1030
|
await this.page.evaluate(`
|
|
@@ -858,23 +1050,13 @@ var XBLocatorImpl = class _XBLocatorImpl {
|
|
|
858
1050
|
async press(key, opts = {}) {
|
|
859
1051
|
await waitForActionable(this.page, this.selector, { timeout: opts.timeout });
|
|
860
1052
|
await scrollIntoView(this.page, this.selector);
|
|
861
|
-
await this.
|
|
862
|
-
(function() {
|
|
863
|
-
const el = ${this._q(this.selector)};
|
|
864
|
-
if (el) el.focus();
|
|
865
|
-
})()
|
|
866
|
-
`);
|
|
1053
|
+
await this.click({ timeout: opts.timeout });
|
|
867
1054
|
await this.page.keyboard.press(key);
|
|
868
1055
|
}
|
|
869
1056
|
async pressSequentially(text, opts = {}) {
|
|
870
1057
|
await waitForActionable(this.page, this.selector, { timeout: opts.timeout });
|
|
871
1058
|
await scrollIntoView(this.page, this.selector);
|
|
872
|
-
await this.
|
|
873
|
-
(function() {
|
|
874
|
-
const el = ${this._q(this.selector)};
|
|
875
|
-
if (el) el.focus();
|
|
876
|
-
})()
|
|
877
|
-
`);
|
|
1059
|
+
await this.click({ timeout: opts.timeout });
|
|
878
1060
|
await this.page.keyboard.type(text, { delay: opts.delay });
|
|
879
1061
|
}
|
|
880
1062
|
async hover(opts = {}) {
|
|
@@ -929,11 +1111,36 @@ var XBLocatorImpl = class _XBLocatorImpl {
|
|
|
929
1111
|
async selectOption(value) {
|
|
930
1112
|
await waitForActionable(this.page, this.selector);
|
|
931
1113
|
const values = Array.isArray(value) ? value : [value];
|
|
932
|
-
const
|
|
1114
|
+
const info = await this.page.evaluate(`
|
|
933
1115
|
(function() {
|
|
934
1116
|
const el = ${this._q(this.selector)};
|
|
935
1117
|
if (!el || el.tagName !== 'SELECT') throw new Error('Not a select element');
|
|
936
|
-
|
|
1118
|
+
const values = ${JSON.stringify(values)};
|
|
1119
|
+
let target = -1, targetValue = '';
|
|
1120
|
+
outer:
|
|
1121
|
+
for (let i = 0; i < el.options.length; i++) {
|
|
1122
|
+
const opt = el.options[i];
|
|
1123
|
+
for (const v of values) {
|
|
1124
|
+
const hit = typeof v === 'object'
|
|
1125
|
+
? (v.label !== undefined ? opt.label === v.label
|
|
1126
|
+
: v.value !== undefined ? opt.value === v.value
|
|
1127
|
+
: opt.index === v.index)
|
|
1128
|
+
: (opt.value === v || opt.label === v);
|
|
1129
|
+
if (hit) { target = i; targetValue = opt.value; break outer; }
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return { cur: el.selectedIndex, target: target, targetValue: targetValue, multiple: el.multiple };
|
|
1133
|
+
})()
|
|
1134
|
+
`);
|
|
1135
|
+
if (info.target < 0) {
|
|
1136
|
+
throw new Error(`Option not found: ${JSON.stringify(values)}`);
|
|
1137
|
+
}
|
|
1138
|
+
if (!info.multiple) {
|
|
1139
|
+
await this.click({ timeout: 5e3 });
|
|
1140
|
+
}
|
|
1141
|
+
const selected = await this.page.evaluate(`
|
|
1142
|
+
(function() {
|
|
1143
|
+
const el = ${this._q(this.selector)};
|
|
937
1144
|
const values = ${JSON.stringify(values)};
|
|
938
1145
|
const selectedValues = [];
|
|
939
1146
|
|
|
@@ -4569,6 +4776,9 @@ async function launch(options = {}) {
|
|
|
4569
4776
|
}
|
|
4570
4777
|
|
|
4571
4778
|
export {
|
|
4779
|
+
rand,
|
|
4780
|
+
sleep,
|
|
4781
|
+
wheelDelta,
|
|
4572
4782
|
XBMouseImpl,
|
|
4573
4783
|
XBKeyboardImpl,
|
|
4574
4784
|
waitForActionable,
|