dsh-browser-cdp 1.14.4 → 1.14.6

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/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## 1.14.6 (2026-11-22)
2
+
3
+ **JS 弹窗可见性(上游 #104 同构):卡住的步骤从裸超时变成自带「dialog 类型 + 页面 message + 处置指引」的诊断。**
4
+
5
+ 反向审计确认的第二个平行面:worker 的消息循环忽略一切事件,`Page.javascriptDialogOpening/Closed` 从未被消费——而弹窗打开时渲染器主线程冻结,后续页面型 CDP 调用全部挂起,agent 看到的只是莫名超时(`Input.dispatchMouseEvent timed out after 15000ms`),没有任何线索指向弹窗。手动处置工具(`Page.handleJavaScriptDialog`)一直存在,缺的是「知道要去找它」。
6
+
7
+ - **修复**:worker 在事件流上跟踪弹窗生命周期(`Page.enable` 已在 attachPage 开启,事件本就在流上):`javascriptDialogOpening` → `state.dialog = { type, message, url }`,`Closed` 清空。**失败路径**:步骤错误消息追加 `(a JavaScript dialog (type "alert", message "…") is open on the page - dismiss it with Page.handleJavaScriptDialog before retrying)`。**成功路径**:capture/act/navigate/interactive 回包在弹窗打开时携带 `dialog` 字段(页面冻结状态如实呈现)。effects 侧 `CaptureReply.dialog?` / `ActReply.dialog?` 契约字段。
8
+ - **决策**:只可见性、不自动 dismiss——agent 保留知情权,自动关闭可能吞掉页面必需的 confirm 流程;手动工具是正道。
9
+ - **E2E 实测**(Chrome 158 headless):alert 按钮页点击 → `Input.dispatchMouseEvent timed out after 15000ms (a JavaScript dialog (type "alert", message "blocked!") is open on the page - dismiss it with Page.handleJavaScriptDialog before retrying)`(修复前 = 裸超时零诊断);无弹窗对照 → `ok=True` 且无 dialog 字段泄漏。
10
+ - **测试设计注记**:gather 与 act 必须同文档(跨进程重导航会使 backendNodeId 失效)——首轮 E2E 的 no-box-model 假阴性即此因。
11
+
12
+ 门禁:`npm run typecheck` 干净;`npm test` **1342 passed / 13 skipped**(+2 契约用例:弹窗生命周期跟踪、失败消息与成功回包的 dialog 面);worker 为直维护 .mjs 无构建面,lib 因 effects.ts 契约字段重建。
13
+
14
+ ## 1.14.5 (2026-11-22)
15
+
16
+ **scroll 行为诚实化(上游 #109 同构)+ 修复 jev 循环 scroll 全灭的潜伏缺陷。**
17
+
18
+ 反向审计上游 `omdsh-dev/dsh-ego-browser` 的 issue 历史时确认的平行面(他们 #109 → PR #110):
19
+
20
+ - **潜伏缺陷(更硬)**:worker 把 scroll 分支放在 `backendNodeId <= 0` 守卫**之后**,而 jev 循环的 act 对 scroll 发送 `backendNodeId: 0`(页面级动作无目标)——**每一条循环驱动的 scroll 都以 `no-candidate` 失败**,scroll 分支经唯一调用方是完全的死代码。reload 同为页面级动作却在守卫前(其注释明言理由),scroll 漏了同样的待遇。
21
+ - **修复一**:scroll 分支移到守卫之前,与 reload 同序。
22
+ - **修复二(报告语义)**:wheel 派发是协议层 fire-and-forget——渲染器异步生效。现在 wheel 前后各读一次 `readScroll()`(基建已有),派发后做**双稳定读轮询**(连续两次相同才停,有界 ~600ms;单次固定 settle 观测到过一次读早于生效),回包新增 `scroll: { moved, before, after }`——页面滚不动时**如实报 `moved:false` 而非谎报成功**;jev verify 兜底语义不变。契约类型:`ActOk.scroll?`(act.ts)/ `ActReply.scroll?`(effects.ts)透传。
23
+
24
+ **E2E 实测**(Chrome 158 headless):长页(3000px 可滚)→ `ok=True moved=true after={0,600}`,后续 capture 复核 `viewport.scrollY=600`;短页(无溢出)→ `ok=True moved=false`(诚实报告,不再谎报成功)。原生 CDP 分时间点取证:wheel 50ms 内生效,证明双稳定轮询覆盖。
25
+
26
+ 门禁:`npm run typecheck` 干净;`npm test` **1340 passed / 13 skipped**(+2 契约用例:scroll 先于守卫序位、wheel 前后读序 + 稳定轮询形态);worker 为直维护 .mjs 无构建面,lib 因 act.ts/effects.ts 契约字段重建。
27
+
1
28
  ## 1.14.4 (2026-11-22)
2
29
 
3
30
  **点击未映射点位按 unverified 放行(#18):`Number(undefined)` 的 NaN 比较不再把「未知」折叠成「确定 miss」。**
@@ -47,6 +47,8 @@ let state = {
47
47
  sessionId: '',
48
48
  targetId: '',
49
49
  targetUrl: '',
50
+ /** Open JavaScript dialog (alert/confirm/prompt), if any — see the event interceptor below. */
51
+ dialog: null,
50
52
  }
51
53
 
52
54
  function log(message) {
@@ -133,7 +135,25 @@ async function connect(wsUrl, timeoutMs) {
133
135
  ws.addEventListener('message', (event) => {
134
136
  let message
135
137
  try { message = JSON.parse(String(event.data)) } catch { return }
136
- if (typeof message.id !== 'number') return // an event, not a reply
138
+ if (typeof message.id !== 'number') {
139
+ // An EVENT, not a reply. The only family this worker cares about is the
140
+ // JavaScript dialog lifecycle: while a dialog is open the renderer's
141
+ // main thread is frozen, so every page-facing call would hang into an
142
+ // opaque timeout. Recording it here is what lets a failing step SAY
143
+ // "a dialog is open" instead of a bare timeout (upstream dsh-ego-browser
144
+ // issue #104's failure mode). Page.enable is already on (attachPage),
145
+ // so these events are already flowing.
146
+ if (message.method === 'Page.javascriptDialogOpening') {
147
+ state.dialog = {
148
+ type: String(message.params?.type || 'unknown'),
149
+ message: String(message.params?.message || ''),
150
+ url: String(message.params?.url || ''),
151
+ }
152
+ } else if (message.method === 'Page.javascriptDialogClosed') {
153
+ state.dialog = null
154
+ }
155
+ return
156
+ }
137
157
  const entry = state.pending.get(message.id)
138
158
  if (!entry) return
139
159
  clearTimeout(entry.timer)
@@ -382,10 +402,15 @@ async function actOnCandidate(params) {
382
402
  }
383
403
  }
384
404
 
385
- if (!Number.isFinite(backendNodeId) || backendNodeId <= 0) {
386
- return { ok: false, code: 'no-candidate', message: 'act needs a positive backendNodeId' }
387
- }
388
-
405
+ // Scroll is a PAGE-level action like reload: the caller sends no candidate
406
+ // (backendNodeId 0), so it must be decided BEFORE the candidate guard —
407
+ // otherwise every loop-driven scroll dies as `no-candidate`. The wheel
408
+ // dispatch is fire-and-forget at the protocol level (the renderer applies it
409
+ // asynchronously), so the offsets are read before the dispatch and after a
410
+ // short settle, and `moved` says whether THIS event actually scrolled the
411
+ // page — a success that a page which cannot scroll still reports honestly,
412
+ // with moved:false (the same reporting fix upstream dsh-ego-browser shipped
413
+ // for ego_scroll, their issue #109).
389
414
  if (action === 'scroll') {
390
415
  const deltaY = Number(params.deltaY)
391
416
  if (!Number.isFinite(deltaY) || deltaY === 0) {
@@ -394,10 +419,35 @@ async function actOnCandidate(params) {
394
419
  // A wheel event needs a point; the viewport centre is neutral and needs no
395
420
  // measurement.
396
421
  const centre = await viewportCentre()
422
+ const before = await readScroll()
397
423
  await call('Input.dispatchMouseEvent', {
398
424
  type: 'mouseWheel', x: centre.x, y: centre.y, deltaX: 0, deltaY, button: 'none', buttons: 0, clickCount: 0,
399
425
  })
400
- return { ok: true, code: 'ok', action: 'scroll', backendNodeId: 0, point: centre, measured: null, drift: 0 }
426
+ // One fixed settle can read before the renderer applies the wheel (observed
427
+ // once as moved:false on a page that provably scrolled). Poll until the
428
+ // offset holds stable across two consecutive reads, bounded at ~600ms —
429
+ // cheap insurance for a scroll action that is rare in the loop.
430
+ let after = await readScroll()
431
+ for (let stable = 0, i = 0; i < 4 && stable < 2; i++) {
432
+ await new Promise((resolve) => setTimeout(resolve, 150))
433
+ const next = await readScroll()
434
+ stable = next.x === after.x && next.y === after.y ? stable + 1 : 0
435
+ after = next
436
+ }
437
+ return {
438
+ ok: true,
439
+ code: 'ok',
440
+ action: 'scroll',
441
+ backendNodeId: 0,
442
+ point: centre,
443
+ measured: null,
444
+ drift: 0,
445
+ scroll: { moved: before.x !== after.x || before.y !== after.y, before, after },
446
+ }
447
+ }
448
+
449
+ if (!Number.isFinite(backendNodeId) || backendNodeId <= 0) {
450
+ return { ok: false, code: 'no-candidate', message: 'act needs a positive backendNodeId' }
401
451
  }
402
452
 
403
453
  if (action === 'fill') {
@@ -724,9 +774,22 @@ rl.on('line', (line) => {
724
774
  const id = request.id ?? null
725
775
  try {
726
776
  const result = await handle(String(request.method || ''), request.params || {})
727
- reply(id, true, { result })
777
+ // A page-facing reply while a dialog is open carries the dialog state:
778
+ // the screenshot/script went through, but the page is frozen behind it.
779
+ const method = String(request.method || '')
780
+ const withDialog = state.dialog && (method === 'capture' || method === 'act' || method === 'navigate' || method === 'interactive')
781
+ ? { ...result, dialog: state.dialog }
782
+ : result
783
+ reply(id, true, { result: withDialog })
728
784
  } catch (error) {
729
- reply(id, false, { error: { code: 'call-failed', message: error instanceof Error ? error.message : String(error) } })
785
+ const message = error instanceof Error ? error.message : String(error)
786
+ // The renderer is frozen behind the dialog, so a failing step is far
787
+ // more likely to BE the dialog than an ordinary timeout — say so where
788
+ // the caller can read it, instead of an opaque hang.
789
+ const dialogNote = state.dialog
790
+ ? ` (a JavaScript dialog (type "${state.dialog.type}", message "${state.dialog.message}") is open on the page - dismiss it with Page.handleJavaScriptDialog before retrying)`
791
+ : ''
792
+ reply(id, false, { error: { code: 'call-failed', message: message + dialogNote } })
730
793
  }
731
794
  })
732
795
  })
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "1.14.4",
5
+ "version": "1.14.6",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/index.js CHANGED
@@ -9611,6 +9611,7 @@ function makeJudgeEffects(deps) {
9611
9611
  height: 0
9612
9612
  },
9613
9613
  drift: reply.drift ?? 0,
9614
+ ...reply.scroll === void 0 ? {} : { scroll: reply.scroll },
9614
9615
  ...reply.recorded === void 0 ? {} : { recorded: reply.recorded }
9615
9616
  };
9616
9617
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.14.4",
3
+ "version": "1.14.6",
4
4
  "description": "dsh-browser-cdp: visible agent browser for DSH — drives the vendored ego-compatible Chromium over CDP, and can also attach to a running Chrome/Edge/Brave or route through egolite, Tabbit and Lightpanda backends. 35 structured bcdp_* tools; only bcdp_status stays resident by default (lazy injection, −91.9% schema per turn for non-browser sessions). Realtime watch panel with direct click/scroll/IME input, element picks quoted into the composer, human-verification notices; non-CDP channels sync frames by 3s polling. Web shell: floating watch ball without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.0-rc.2 ~ 0.2.2-rc.1: declarative settings via Config .volatile() fields on 0.1.7+; imperative installSection / module-level registration + describe/mutate bridge on 0.1.0 ~ 0.1.5 (experimental, pending farm). Client peers stay optional so gen-1 hosts without dsh-client-store still load; for a production install on the current line use the 0.17.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",