@xbrowser/cli 1.29.0 → 1.30.1

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.
Files changed (36) hide show
  1. package/README.md +2 -2
  2. package/dist/{browser-XD3IOU5I.js → browser-6PFTHZI3.js} +2 -2
  3. package/dist/{browser-2K3XYAKM.js → browser-I2NLJN2A.js} +1 -1
  4. package/dist/{browser-OTEMG5NL.js → browser-KOUA4ZDA.js} +2 -2
  5. package/dist/{cdp-driver-AAS55KT2.js → cdp-driver-3ETNFQA4.js} +1 -1
  6. package/dist/{cdp-driver-XTPY7EXP.js → cdp-driver-U7HDQMQ5.js} +257 -19
  7. package/dist/{cdp-driver-O5I7SJ24.js → cdp-driver-WBFJNOLD.js} +1 -1
  8. package/dist/{chunk-SCYBNSOG.js → chunk-3K57RYVC.js} +378 -115
  9. package/dist/{chunk-FNXA6FDM.js → chunk-BND5O5KC.js} +2 -1
  10. package/dist/{chunk-P33R7F2D.js → chunk-BOZTIIBT.js} +30 -45
  11. package/dist/{chunk-GDKKVT2P.js → chunk-KPTD3SNJ.js} +379 -116
  12. package/dist/{chunk-CO2ZVOVT.js → chunk-NINETOM4.js} +30 -45
  13. package/dist/{chunk-SOPN4XDK.js → chunk-O5PASNI7.js} +2 -1
  14. package/dist/{chunk-NQPXZ74W.js → chunk-OCECE22C.js} +257 -19
  15. package/dist/{chunk-LFSLNHW5.js → chunk-OSIDUT4H.js} +286 -63
  16. package/dist/{chunk-HBMEFSTB.js → chunk-QCV2PI7U.js} +2 -1
  17. package/dist/{chunk-UZ6XPUBD.js → chunk-RMYKVZIZ.js} +78 -0
  18. package/dist/{chunk-N5XTLNKS.js → chunk-SPNWUUHA.js} +257 -19
  19. package/dist/{chunk-PGKV24QN.js → chunk-TBJUSUKF.js} +1 -1
  20. package/dist/{chunk-FCPVQFTQ.js → chunk-VYTQLZAX.js} +78 -0
  21. package/dist/cli.js +45 -16
  22. package/dist/daemon-main.js +581 -157
  23. package/dist/{human-interaction-CTZ4IWXJ.js → human-interaction-ISMMOJOK.js} +2 -2
  24. package/dist/{human-interaction-HJCK45SL.js → human-interaction-STTZZZ5N.js} +1 -1
  25. package/dist/{human-interaction-V3VDGHHI.js → human-interaction-UXFYV7DU.js} +1 -1
  26. package/dist/index.d.ts +106 -12
  27. package/dist/index.js +195 -46
  28. package/dist/{recovery-EBKORYEU.js → recovery-JFGV3DBX.js} +1 -1
  29. package/dist/{recovery-5C4FBA5O.js → recovery-ORHJSBDN.js} +2 -2
  30. package/dist/{recovery-IMZUGWSS.js → recovery-XDKN63O5.js} +1 -1
  31. package/dist/{server-ZTI2K5YJ.js → server-TG47W7MV.js} +3 -3
  32. package/dist/{server-LNZTDAKT.js → server-U3YAX5MJ.js} +2 -2
  33. package/dist/{session-recorder-DF2YGH2E.js → session-recorder-N7VEKJVW.js} +1 -1
  34. package/dist/{session-recorder-R3GDGXLJ.js → session-recorder-RUNQOJ7T.js} +1 -1
  35. package/dist/{session-replayer-CLTZ2URU.js → session-replayer-XLWQ47BB.js} +1 -1
  36. package/package.json +4 -1
@@ -33,12 +33,16 @@ import { EventEmitter as EventEmitter2 } from "events";
33
33
  import { EventEmitter } from "events";
34
34
 
35
35
  // src/cdp-driver/mouse.ts
36
+ function buttonBit(button) {
37
+ return button === "left" ? 1 : button === "right" ? 2 : 4;
38
+ }
36
39
  var XBMouseImpl = class {
37
40
  conn;
38
41
  sessionId;
39
42
  _x = 0;
40
43
  _y = 0;
41
44
  _button = "none";
45
+ _buttons = 0;
42
46
  constructor(conn, sessionId) {
43
47
  this.conn = conn;
44
48
  this.sessionId = sessionId;
@@ -69,7 +73,7 @@ var XBMouseImpl = class {
69
73
  _truncated = true;
70
74
  break;
71
75
  }
72
- await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: p.x, y: p.y, button: this._button });
76
+ await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: p.x, y: p.y, button: this._button, buttons: this._buttons });
73
77
  this._x = p.x;
74
78
  this._y = p.y;
75
79
  await sleep(p.delay);
@@ -77,7 +81,7 @@ var XBMouseImpl = class {
77
81
  this._x = tx;
78
82
  this._y = ty;
79
83
  if (_truncated) {
80
- await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: tx, y: ty, button: this._button });
84
+ await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: tx, y: ty, button: this._button, buttons: this._buttons });
81
85
  }
82
86
  await sleep(rand(...DEFAULT_STEALTH_CONFIG.aimPause));
83
87
  } else {
@@ -89,7 +93,7 @@ var XBMouseImpl = class {
89
93
  const ry = stealth ? this._y + rand(...DEFAULT_STEALTH_CONFIG.releaseDrift) * (Math.random() < 0.5 ? -1 : 1) : this._y;
90
94
  this._x = rx;
91
95
  this._y = ry;
92
- await this.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: rx, y: ry, button, clickCount: opts.clickCount ?? 1 });
96
+ await this.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: rx, y: ry, button, buttons: this._buttons, clickCount: opts.clickCount ?? 1 });
93
97
  for (let i = 1; i < (opts.clickCount ?? 1); i++) {
94
98
  if (opts.delay) await sleep(opts.delay);
95
99
  await this.down({ button });
@@ -102,11 +106,13 @@ var XBMouseImpl = class {
102
106
  async down(opts = {}) {
103
107
  const button = opts.button ?? "left";
104
108
  this._button = button;
109
+ this._buttons |= buttonBit(button);
105
110
  await this.send("Input.dispatchMouseEvent", {
106
111
  type: "mousePressed",
107
112
  x: this._x,
108
113
  y: this._y,
109
114
  button,
115
+ buttons: this._buttons,
110
116
  // r23: press 必须与 release 声明同一 clickCount——Chrome 按序列计数
111
117
  // 合成 click/dblclick,press 缺声明会把计数器重置(dblclick 永不合成)
112
118
  clickCount: opts.clickCount ?? 1
@@ -120,8 +126,11 @@ var XBMouseImpl = class {
120
126
  x: this._x,
121
127
  y: this._y,
122
128
  button,
129
+ // release 先带位发送再清位(Puppeteer 同序——DOM mouseup 的 buttons 反映释放后状态)
130
+ buttons: this._buttons,
123
131
  clickCount: opts.clickCount ?? 1
124
132
  });
133
+ this._buttons &= ~buttonBit(button);
125
134
  }
126
135
  async move(x, y, opts = {}) {
127
136
  const stealth = opts.stealth ?? process.env.XBROWSER_STEALTH !== "off";
@@ -139,7 +148,8 @@ var XBMouseImpl = class {
139
148
  type: "mouseMoved",
140
149
  x: this._x,
141
150
  y: this._y,
142
- button: this._button
151
+ button: this._button,
152
+ buttons: this._buttons
143
153
  });
144
154
  }
145
155
  this._x = x;
@@ -159,9 +169,11 @@ var XBMouseImpl = class {
159
169
  x: this._x,
160
170
  y: this._y,
161
171
  button: "left",
172
+ buttons: 1,
162
173
  clickCount: 1
163
174
  });
164
175
  this._button = "left";
176
+ this._buttons |= 1;
165
177
  const steps = opts.steps ?? Math.max(10, Math.min(24, Math.round(Math.hypot(x - this._x, y - this._y) / 20)));
166
178
  const fx = this._x, fy = this._y;
167
179
  for (let i = 1; i <= steps; i++) {
@@ -173,7 +185,8 @@ var XBMouseImpl = class {
173
185
  type: "mouseMoved",
174
186
  x: this._x,
175
187
  y: this._y,
176
- button: this._button
188
+ button: this._button,
189
+ buttons: this._buttons
177
190
  });
178
191
  }
179
192
  this._x = x;
@@ -184,15 +197,22 @@ var XBMouseImpl = class {
184
197
  x,
185
198
  y,
186
199
  button: "left",
200
+ buttons: this._buttons,
187
201
  clickCount: 1
188
202
  });
189
203
  this._button = "none";
204
+ this._buttons &= ~1;
205
+ }
206
+ async wheelAt(x, y, deltaX, deltaY) {
207
+ await this.move(x, y);
208
+ await this.wheel(deltaX, deltaY);
190
209
  }
191
210
  async wheel(deltaX, deltaY) {
192
211
  await this.send("Input.dispatchMouseEvent", {
193
212
  type: "mouseWheel",
194
213
  x: this._x,
195
214
  y: this._y,
215
+ buttons: this._buttons,
196
216
  deltaX,
197
217
  deltaY
198
218
  });
@@ -1454,7 +1474,7 @@ var MediaService = class {
1454
1474
  y: Math.round(opts.clip.y),
1455
1475
  width: Math.round(Math.max(1, opts.clip.width)),
1456
1476
  height: Math.round(Math.max(1, opts.clip.height)),
1457
- scale: 1
1477
+ scale: opts.clip.scale ?? 1
1458
1478
  };
1459
1479
  params.clip = clip;
1460
1480
  }
@@ -2451,14 +2471,13 @@ var RuntimeEvaluationService = class {
2451
2471
  }
2452
2472
  return result.result?.value;
2453
2473
  };
2454
- try {
2455
- const tg = await this.options.conn.send("Target.getTargets", void 0);
2456
- const hit2 = (tg.targetInfos || []).find((t) => t.type === "iframe" && (t.url || "").includes(urlIncludes));
2457
- if (hit2) {
2458
- const att = await this.options.conn.send("Target.attachToTarget", { targetId: hit2.targetId, flatten: true });
2459
- return evalIn(att.sessionId);
2474
+ const attachedA = await this.tryAttachViaTargets(urlIncludes);
2475
+ if (attachedA) {
2476
+ try {
2477
+ return await evalIn(attachedA);
2478
+ } finally {
2479
+ this.detachQuietly(attachedA);
2460
2480
  }
2461
- } catch {
2462
2481
  }
2463
2482
  const tree = await this.options.conn.send("Page.getFrameTree", void 0, this.options.sessionId);
2464
2483
  const all = [];
@@ -2486,6 +2505,87 @@ var RuntimeEvaluationService = class {
2486
2505
  const ctx = contexts.find((c) => c.frameId === target.id);
2487
2506
  if (ctx) return evalIn(this.options.sessionId, ctx.id);
2488
2507
  }
2508
+ const attachedC = await this.tryAttachViaAutoAttach(urlIncludes);
2509
+ if (attachedC) {
2510
+ try {
2511
+ return await evalIn(attachedC);
2512
+ } finally {
2513
+ this.detachQuietly(attachedC);
2514
+ }
2515
+ }
2516
+ throw new Error(`frame not found for "${urlIncludes}"\uFF08OOPIF target\u3001frame \u6811\u3001auto-attach \u4E09\u8DEF\u5747\u672A\u547D\u4E2D\uFF1B\u53EF\u80FD\u4ECD\u5728\u52A0\u8F7D\uFF09`);
2517
+ }
2518
+ /**
2519
+ * 输入专用 frame session 解析(mouse/click/fill --frame)。
2520
+ *
2521
+ * 与 evaluateInFrame 的区别:必须拿到**真实 target session**(Input 域
2522
+ * 事件派发到该 session 才会进入 iframe 的渲染进程——主页面 session 上
2523
+ * 派发的输入进不去 OOPIF,qqmail 验证码 4 次页面级拖动全败的实证)。
2524
+ * 因此只走 A(getTargets attach)/ C(auto-attach)两路;同进程 frame
2525
+ * 没有 session,但 locator 层的坐标偏移本就支持同源 iframe,直接用普通
2526
+ * click/fill 即可。
2527
+ *
2528
+ * 坐标语义:返回的 session 上派发 Input 事件用 **iframe 局部坐标**
2529
+ * (与该 session 内 getBoundingClientRect 一致)。
2530
+ */
2531
+ async resolveFrameSession(urlIncludes) {
2532
+ if (this.options.isClosed()) throw new Error("Page is closed");
2533
+ const viaTargets = await this.tryAttachViaTargets(urlIncludes);
2534
+ if (viaTargets) return viaTargets;
2535
+ const viaAuto = await this.tryAttachViaAutoAttach(urlIncludes);
2536
+ if (viaAuto) return viaAuto;
2537
+ try {
2538
+ const tree = await this.options.conn.send("Page.getFrameTree", void 0, this.options.sessionId);
2539
+ const urls = [];
2540
+ const walk = (node) => {
2541
+ urls.push(node.frame.url);
2542
+ for (const child of node.childFrames || []) walk(child);
2543
+ };
2544
+ walk(tree.frameTree);
2545
+ if (urls.some((u) => u.includes(urlIncludes))) {
2546
+ throw new Error(`frame "${urlIncludes}" \u662F\u540C\u8FDB\u7A0B iframe\uFF08\u65E0\u72EC\u7ACB target\uFF09\u2014\u2014\u666E\u901A click/fill/mouse \u5373\u53EF\uFF08locator \u5C42\u5DF2\u652F\u6301\u540C\u6E90 iframe \u5750\u6807\u504F\u79FB\uFF09`);
2547
+ }
2548
+ } catch (err) {
2549
+ if (err instanceof Error && err.message.includes("\u540C\u8FDB\u7A0B")) throw err;
2550
+ }
2551
+ throw new Error(`no OOPIF target for "${urlIncludes}"\uFF08\u7528 'xbrowser frames' \u67E5\u770B\u53EF\u89C1\u7684 iframe target\uFF1BOOPIF \u53EA\u5728 Target.getTargets \u91CC\u51FA\u73B0\uFF09`);
2552
+ }
2553
+ /** 浏览器级 iframe target 列表(OOPIF 可见性——Page.getFrameTree 看不到它们) */
2554
+ async listFrameTargets() {
2555
+ try {
2556
+ const tg = await this.options.conn.send("Target.getTargets", void 0);
2557
+ return (tg.targetInfos || []).filter((t) => t.type === "iframe").map((t) => ({ url: t.url || "", targetId: t.targetId }));
2558
+ } catch {
2559
+ return [];
2560
+ }
2561
+ }
2562
+ /** 路径 A:浏览器级 Target.getTargets 平铺 iframe target,按 URL 子串 attach。
2563
+ * 多次导航后列表里可能残留正在销毁的陈旧 target——attach 后用 location.href
2564
+ * 验证候选确实是活目标,不匹配则换下一个(验证码 iframe 重建场景实测会撞上)。 */
2565
+ async tryAttachViaTargets(urlIncludes) {
2566
+ try {
2567
+ const tg = await this.options.conn.send("Target.getTargets", void 0);
2568
+ const candidates = (tg.targetInfos || []).filter((t) => t.type === "iframe" && (t.url || "").includes(urlIncludes));
2569
+ for (const hit of candidates) {
2570
+ try {
2571
+ const att = await this.options.conn.send("Target.attachToTarget", { targetId: hit.targetId, flatten: true });
2572
+ const probe = await this.options.conn.send("Runtime.evaluate", { expression: "location.href", returnByValue: true }, att.sessionId);
2573
+ const href = typeof probe.result?.value === "string" ? probe.result.value : "";
2574
+ if (probe.exceptionDetails || !href.includes(urlIncludes)) {
2575
+ this.detachQuietly(att.sessionId);
2576
+ continue;
2577
+ }
2578
+ return att.sessionId;
2579
+ } catch {
2580
+ continue;
2581
+ }
2582
+ }
2583
+ } catch {
2584
+ }
2585
+ return null;
2586
+ }
2587
+ /** 路径 C:Target.setAutoAttach 监听后续 attach 的 iframe target(兜底) */
2588
+ async tryAttachViaAutoAttach(urlIncludes) {
2489
2589
  const attached = [];
2490
2590
  const onAttach = (raw) => {
2491
2591
  const ev = raw;
@@ -2507,10 +2607,11 @@ var RuntimeEvaluationService = class {
2507
2607
  });
2508
2608
  }
2509
2609
  const hit = attached.find((a) => a.url.includes(urlIncludes));
2510
- if (!hit) {
2511
- throw new Error(`frame not found for "${urlIncludes}"\uFF08OOPIF target\u3001frame \u6811\u3001auto-attach \u4E09\u8DEF\u5747\u672A\u547D\u4E2D\uFF1B\u53EF\u80FD\u4ECD\u5728\u52A0\u8F7D\uFF09`);
2512
- }
2513
- return evalIn(hit.sessionId);
2610
+ return hit ? hit.sessionId : null;
2611
+ }
2612
+ detachQuietly(sessionId) {
2613
+ this.options.conn.send("Target.detachFromTarget", { sessionId }).catch(() => {
2614
+ });
2514
2615
  }
2515
2616
  /** evaluateHandle — evaluates fn and returns a handle for element bounding box */
2516
2617
  async evaluateHandle(fn, ...args) {
@@ -2562,6 +2663,103 @@ var RuntimeEvaluationService = class {
2562
2663
  }
2563
2664
  };
2564
2665
 
2666
+ // src/cdp-driver/page-frame-input.ts
2667
+ function isSessionDeadError(err) {
2668
+ return /session (with given id )?not found|no session with given id/i.test(errMsg(err));
2669
+ }
2670
+ var FrameInputService = class {
2671
+ constructor(deps) {
2672
+ this.deps = deps;
2673
+ }
2674
+ deps;
2675
+ /** urlIncludes → 已 attach 的 session + 鼠标实例(跨命令保持位置状态) */
2676
+ cache = /* @__PURE__ */ new Map();
2677
+ /**
2678
+ * 拿到指定 OOPIF 的鼠标(Input 域派发进 iframe 渲染进程,isTrusted=true)。
2679
+ * 缓存的 session 失效(iframe 重建/刷新)时自动重 attach;重 attach 会
2680
+ * 重置鼠标位置——调用方需重新读取目标元素坐标。
2681
+ */
2682
+ async frameMouse(urlIncludes, opts = {}) {
2683
+ if (opts.fresh) this.cache.delete(urlIncludes);
2684
+ const cached = this.cache.get(urlIncludes);
2685
+ if (cached) {
2686
+ try {
2687
+ await this.deps.conn.send("Runtime.evaluate", { expression: "1", returnByValue: true }, cached.sessionId);
2688
+ return cached.mouse;
2689
+ } catch {
2690
+ this.cache.delete(urlIncludes);
2691
+ }
2692
+ }
2693
+ const sessionId = await this.deps.resolveFrameSession(urlIncludes);
2694
+ const mouse = new XBMouseImpl(this.deps.conn, sessionId);
2695
+ this.cache.set(urlIncludes, { sessionId, mouse });
2696
+ return mouse;
2697
+ }
2698
+ /**
2699
+ * 带重试的 frame 鼠标操作:Chrome 异步销毁旧 OOPIF target 的窗口期里
2700
+ * (连续导航/验证码 iframe 重建),probe 通过后 dispatch 仍可能撞上死
2701
+ * session——session 失效时强制重 attach 再做一次。
2702
+ */
2703
+ async runFrameMouse(urlIncludes, fn) {
2704
+ try {
2705
+ return await fn(await this.frameMouse(urlIncludes));
2706
+ } catch (err) {
2707
+ if (!isSessionDeadError(err)) throw err;
2708
+ this.cache.delete(urlIncludes);
2709
+ return fn(await this.frameMouse(urlIncludes, { fresh: true }));
2710
+ }
2711
+ }
2712
+ /** 在 OOPIF 内点击选择器命中的元素(frame 局部坐标,stealth 落点偏移继承) */
2713
+ async clickInFrame(urlIncludes, selector, opts = {}) {
2714
+ const rect = await this.pollFrameRect(urlIncludes, selector, opts.timeoutMs ?? 5e3);
2715
+ const x = rect.x + rect.width / 2;
2716
+ const y = rect.y + rect.height / 2;
2717
+ await this.runFrameMouse(urlIncludes, (mouse) => mouse.click(x, y, { elementWidth: rect.width, elementHeight: rect.height }));
2718
+ return { x, y };
2719
+ }
2720
+ /** 在 OOPIF 内填输入框:点击聚焦 → el.select() 全选 → insertText 整体替换 → 回读验证 */
2721
+ async fillInFrame(urlIncludes, selector, text, opts = {}) {
2722
+ try {
2723
+ return await this.fillInFrameInner(urlIncludes, selector, text, opts);
2724
+ } catch (err) {
2725
+ if (!isSessionDeadError(err)) throw err;
2726
+ this.cache.delete(urlIncludes);
2727
+ return this.fillInFrameInner(urlIncludes, selector, text, opts);
2728
+ }
2729
+ }
2730
+ async fillInFrameInner(urlIncludes, selector, text, opts = {}) {
2731
+ await this.clickInFrame(urlIncludes, selector, opts);
2732
+ const cached = this.cache.get(urlIncludes);
2733
+ if (!cached) throw new Error(`frame session lost for "${urlIncludes}"`);
2734
+ await this.deps.evaluateInFrame(
2735
+ urlIncludes,
2736
+ `(() => { const el = document.querySelector(${JSON.stringify(selector)}); if (el && typeof el.select === 'function') el.select(); return true; })()`
2737
+ );
2738
+ await this.deps.conn.send("Input.insertText", { text }, cached.sessionId);
2739
+ const readback = await this.deps.evaluateInFrame(
2740
+ urlIncludes,
2741
+ `(() => { const el = document.querySelector(${JSON.stringify(selector)}); return el ? String(el.value ?? '') : ''; })()`
2742
+ );
2743
+ return { value: readback ?? "" };
2744
+ }
2745
+ /** 轮询 OOPIF 内元素 rect(等待元素出现/可测量) */
2746
+ async pollFrameRect(urlIncludes, selector, timeoutMs) {
2747
+ const expr = `(() => { const el = document.querySelector(${JSON.stringify(selector)}); if (!el) return null; const r = el.getBoundingClientRect(); if (r.width === 0 || r.height === 0) return null; return { x: r.x, y: r.y, width: r.width, height: r.height }; })()`;
2748
+ const deadline = Date.now() + timeoutMs;
2749
+ let lastErr;
2750
+ while (Date.now() < deadline) {
2751
+ try {
2752
+ const rect = await this.deps.evaluateInFrame(urlIncludes, expr);
2753
+ if (rect) return rect;
2754
+ } catch (err) {
2755
+ lastErr = err;
2756
+ }
2757
+ await new Promise((r) => setTimeout(r, 200));
2758
+ }
2759
+ throw new Error(`[frame ${urlIncludes}] element "${selector}" not found/visible within ${timeoutMs}ms${lastErr instanceof Error ? `\uFF08last: ${lastErr.message}\uFF09` : ""}`);
2760
+ }
2761
+ };
2762
+
2565
2763
  // src/cdp-driver/page.ts
2566
2764
  var XBPageImpl = class _XBPageImpl {
2567
2765
  conn;
@@ -2588,6 +2786,7 @@ var XBPageImpl = class _XBPageImpl {
2588
2786
  navigationService;
2589
2787
  domQueryService;
2590
2788
  runtimeEvaluationService;
2789
+ frameInputService;
2591
2790
  // Network tracking for waitForLoadState('networkidle')
2592
2791
  inflightRequests = /* @__PURE__ */ new Set();
2593
2792
  networkIdleResolve = null;
@@ -2650,6 +2849,11 @@ var XBPageImpl = class _XBPageImpl {
2650
2849
  isClosed: () => this._closed,
2651
2850
  url: () => this.url()
2652
2851
  });
2852
+ this.frameInputService = new FrameInputService({
2853
+ conn,
2854
+ resolveFrameSession: (urlIncludes) => this.runtimeEvaluationService.resolveFrameSession(urlIncludes),
2855
+ evaluateInFrame: (urlIncludes, expression) => this.evaluateInFrame(urlIncludes, expression)
2856
+ });
2653
2857
  this.domQueryService = new DomQueryService({
2654
2858
  conn,
2655
2859
  sessionId,
@@ -2859,8 +3063,9 @@ var XBPageImpl = class _XBPageImpl {
2859
3063
  "Target.getTargetInfo",
2860
3064
  { targetId: this._targetId }
2861
3065
  );
2862
- this._url = info.url;
2863
- if (info.url && info.url !== "about:blank" && info.url !== "") {
3066
+ const curUrl = info.targetInfo?.url ?? info.url;
3067
+ if (curUrl) this._url = curUrl;
3068
+ if (curUrl && curUrl !== "about:blank" && curUrl !== "") {
2864
3069
  this._loadState = { loadFired: true, domContentFired: true, networkIdle: true };
2865
3070
  }
2866
3071
  } catch {
@@ -2984,6 +3189,29 @@ Last error: ${lastError.message}` : "";
2984
3189
  async evaluateInFrame(urlIncludes, expression) {
2985
3190
  return this.runtimeEvaluationService.evaluateInFrame(urlIncludes, expression);
2986
3191
  }
3192
+ /** 浏览器级 iframe target 列表(OOPIF 可见——frames 命令用) */
3193
+ async listFrameTargets() {
3194
+ return this.runtimeEvaluationService.listFrameTargets();
3195
+ }
3196
+ /**
3197
+ * 拿到指定 OOPIF 的鼠标(Input 域派发进 iframe 渲染进程,isTrusted=true)。
3198
+ * 坐标语义:iframe 局部坐标(与该 session 内 getBoundingClientRect 一致)。
3199
+ * session 失效自动重 attach(鼠标位置会重置,需重读目标坐标)。
3200
+ */
3201
+ async frameMouse(urlIncludes, opts) {
3202
+ return this.frameInputService.frameMouse(urlIncludes, opts);
3203
+ }
3204
+ async runFrameMouse(urlIncludes, fn) {
3205
+ return this.frameInputService.runFrameMouse(urlIncludes, fn);
3206
+ }
3207
+ /** 在 OOPIF 内点击选择器命中的元素(轮询等待 + stealth 落点) */
3208
+ async clickInFrame(urlIncludes, selector, opts) {
3209
+ return this.frameInputService.clickInFrame(urlIncludes, selector, opts);
3210
+ }
3211
+ /** 在 OOPIF 内填输入框(点击聚焦 + insertText + 回读) */
3212
+ async fillInFrame(urlIncludes, selector, text, opts) {
3213
+ return this.frameInputService.fillInFrame(urlIncludes, selector, text, opts);
3214
+ }
2987
3215
  async evaluateHandle(script, ...args) {
2988
3216
  return this.runtimeEvaluationService.evaluateHandle(script, ...args);
2989
3217
  }
@@ -3714,6 +3942,16 @@ var XBBrowserImpl = class {
3714
3942
  await this.conn.close();
3715
3943
  this._emitter.emit("disconnected");
3716
3944
  }
3945
+ async disconnect() {
3946
+ if (this._disconnected) return;
3947
+ this._disconnected = true;
3948
+ if (this._exitHandler) {
3949
+ process.removeListener("exit", this._exitHandler);
3950
+ this._exitHandler = null;
3951
+ }
3952
+ await this.conn.close();
3953
+ this._emitter.emit("disconnected");
3954
+ }
3717
3955
  async newContext(opts = {}) {
3718
3956
  if (this.launchOpts?.stealthConfig && !opts.stealthConfig) {
3719
3957
  opts = { ...opts, stealthConfig: this.launchOpts.stealthConfig };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ScreencastCapturer,
3
3
  getCaptchaConfig
4
- } from "./chunk-HBMEFSTB.js";
4
+ } from "./chunk-QCV2PI7U.js";
5
5
 
6
6
  // src/human-interaction.ts
7
7
  import { execFile } from "child_process";
@@ -2646,6 +2646,82 @@ async function injectActionScript(page) {
2646
2646
  // src/recorder/summary-builder.ts
2647
2647
  var POST_WINDOW = 5e3;
2648
2648
  var MERGE_WINDOW = 2e3;
2649
+ var COMPACT_MAX_FLOW_ITEMS = 100;
2650
+ var COMPACT_MAX_API_ITEMS = 20;
2651
+ function buildCompactSummary(data, startedAt) {
2652
+ const flow = [];
2653
+ let lastInputKey = "";
2654
+ const events = [
2655
+ ...data.actions.map((action) => ({ timestamp: action.timestamp, action })),
2656
+ ...data.contextChanges.map((contextChange) => ({ timestamp: contextChange.timestamp, contextChange }))
2657
+ ].sort((a, b) => a.timestamp - b.timestamp);
2658
+ for (const event of events) {
2659
+ if (flow.length >= COMPACT_MAX_FLOW_ITEMS) break;
2660
+ if (event.contextChange) {
2661
+ if (event.contextChange.type !== "navigate" || !event.contextChange.url) continue;
2662
+ lastInputKey = "";
2663
+ flow.push({
2664
+ step: flow.length + 1,
2665
+ action: `navigate ${event.contextChange.url}`
2666
+ });
2667
+ continue;
2668
+ }
2669
+ const action = event.action;
2670
+ if (!action) continue;
2671
+ const selector = action.element?.selector || action.element?.ariaLabel || action.element?.placeholder || action.element?.tag || "";
2672
+ const text = (action.element?.text || "").trim();
2673
+ const target = selector || text || action.url || "unknown";
2674
+ let description = "";
2675
+ if (action.type === "input" || action.type === "cdp-fill") {
2676
+ const inputKey = `${action.type}|${target}`;
2677
+ if (inputKey === lastInputKey) continue;
2678
+ lastInputKey = inputKey;
2679
+ description = `fill ${target} value=${truncate(action.value || "", 60)}`;
2680
+ } else if (action.type === "click" || action.type === "cdp-click") {
2681
+ lastInputKey = "";
2682
+ description = `click ${target}${text ? ` text=${truncate(text, 60)}` : ""}`;
2683
+ } else if (action.type === "change") {
2684
+ lastInputKey = "";
2685
+ description = `change ${target} value=${truncate(action.value || "", 60)}`;
2686
+ } else if (action.type === "submit") {
2687
+ lastInputKey = "";
2688
+ description = `submit ${target}`;
2689
+ } else if (action.type === "hover") {
2690
+ lastInputKey = "";
2691
+ description = `hover ${target}`;
2692
+ } else if (action.type === "drag") {
2693
+ lastInputKey = "";
2694
+ description = `drag from (${action.drag?.fromX ?? 0},${action.drag?.fromY ?? 0}) to (${action.drag?.toX ?? 0},${action.drag?.toY ?? 0})`;
2695
+ } else if (action.type === "drop") {
2696
+ lastInputKey = "";
2697
+ description = `drop ${action.files?.count ?? 1} file(s) on ${target}`;
2698
+ } else {
2699
+ continue;
2700
+ }
2701
+ flow.push({ step: flow.length + 1, action: description });
2702
+ }
2703
+ const keyApis = data.network.filter((entry) => (entry.resourceType === "fetch" || entry.resourceType === "xhr") && entry.contentType.toLowerCase().includes("json")).sort((a, b) => b.responseSize - a.responseSize).slice(0, COMPACT_MAX_API_ITEMS).map((entry) => ({
2704
+ method: entry.method,
2705
+ url: entry.url,
2706
+ path: entry.path,
2707
+ status: entry.status,
2708
+ contentType: entry.contentType,
2709
+ responseSize: entry.responseSize,
2710
+ ...entry.requestBody === void 0 ? {} : { requestBody: entry.requestBody }
2711
+ }));
2712
+ return {
2713
+ startUrl: data.startUrl,
2714
+ recordedAt: new Date(startedAt).toISOString(),
2715
+ durationMs: Math.max(0, Date.now() - startedAt),
2716
+ totalActions: data.actions.length,
2717
+ totalNetworkRequests: data.network.length,
2718
+ flow,
2719
+ keyApis
2720
+ };
2721
+ }
2722
+ function truncate(value, maxLength) {
2723
+ return value.length > maxLength ? `${value.slice(0, Math.max(0, maxLength - 3))}...` : value;
2724
+ }
2649
2725
  function buildSummary(data, startedAt) {
2650
2726
  const steps = [];
2651
2727
  const selectorToRef = /* @__PURE__ */ new Map();
@@ -3959,6 +4035,8 @@ var SessionRecorder = class _SessionRecorder {
3959
4035
  const lines = data.actions.map((a) => JSON.stringify(a)).join("\n") + "\n";
3960
4036
  writeFileSync3(jsonlPath, lines, "utf-8");
3961
4037
  writeFileSync3(join4(this.recordingsDir, "summary.json"), JSON.stringify(summary, null, 2), "utf-8");
4038
+ const compactSummary = buildCompactSummary(data, this.startedAt);
4039
+ writeFileSync3(join4(this.recordingsDir, "summary-compact.json"), JSON.stringify(compactSummary, null, 2), "utf-8");
3962
4040
  writeFileSync3(join4(this.recordingsDir, "summary.md"), buildMarkdownSummary(data, summary), "utf-8");
3963
4041
  }
3964
4042
  buildData() {