Skip to content

fix(browser-control): connect to guarded CDP without /json endpoints - #3668

Merged
bobleer merged 5 commits into
openBitFun:mainfrom
bobleer:bob/browser-control-guarded-cdp
Nov 2, 2026
Merged

bobleer merged 5 commits into
openBitFun:mainfrom
bobleer:bob/browser-control-guarded-cdp

Conversation

@bobleer

@bobleer bobleer commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

支持 Chrome/Edge 用户批准式(guarded)remote debugging:/json* 返回 404 时,经验证后使用 browser WebSocket,不再把所有 CDP 服务都当作旧式 HTTP discovery。同步贯通 Settings、Peer Host 和 relay 的授权等待预算。

Fixes #3654

Type and Areas

Bug fix — browser-control provider、Core CDP/ControlHub、Desktop browser setup 与 account RPC、Web UI Settings/Peer adapter、对应的 Tokio owner contract。

Root cause and changes

  • Guarded Chromium 可能只提供 /devtools/browser WebSocket,且默认 profile 目录中找不到 DevToolsActivePort。现在先找已发布端点,再结合“所选浏览器正在运行”“其他浏览器未声明占用端口”等条件推断候选;HTTP 404 本身不是已连接或已授权的证据。
  • 连接后验证 Browser.getVersion;Chrome/Edge 不匹配时断开、不保留连接。两个浏览器同时运行且端点仅靠端口推断时,startup 不自动发起可能落到另一浏览器的授权请求。
  • 仅 WebSocket upgrade 的 404 可以回到 setup;401/403、其他握手错误、超时和产品不匹配都保留为失败。已用真实 loopback HTTP mock 复现并修复原 review patch 把 401/403 也当作 setup fallback 的问题。
  • 仅对连接被拒绝或升级前快速 reset 做有限退避;已等待授权的握手超时不重连,避免重复提示。
  • Profile 查找覆盖支持的渠道目录;没有活跃端点时,只接受 stable 的 Local State 作为默认浏览器设置证据。文件、进程与同步 TCP 探测移到 spawn_blocking;setup 轮询使用时间截止而非次数预算。
  • UI setup 请求 190 秒、Peer adapter 185 秒、目标 Host invoke 180 秒。补齐原先仍被 account clamp / realtime 固定 120 秒截断的路径,将请求预算一直带到既有 relay timeoutMs;普通调用维持原有 120 秒默认及 ACK/overall 余量。
  • browser-control 仅新增它实际需要的 tokio/rt,同步更新精确 owner contract,并增加移除该依赖后必须报错的 mutation test;未扩大根工作区 Tokio features。
  • 进程检测改为精确进程名匹配(macOS/Linux pgrep -x,Windows tasklist 映像名),不再用 pgrep -f chrome 误匹配 Electron 的 chrome_crashpad_handler。单次 setup 内缓存运行状态(最多 3 秒刷新一次),且仅在端口探测与端口占用检查通过后才查询。
  • 一次 setup 命令使用统一的 170 秒总截止时间(低于 Peer Host 180 秒);迟到的 upgrade 404 回退时,回退 setup 等待与授权等待都只使用剩余时间,耗尽时返回明确失败。

Verification

  • cargo test --locked -p openbitfun-services-integrations --no-default-features --features browser-control --lib browser_control:: — 26 passed(含精确进程名、运行状态缓存、非 404 端口不查询进程的测试)。
  • cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,tools-browser-web,git --lib -- browser_control:: control_hub — 101 passed,2 ignored。
  • cargo test --locked -p openbitfun-desktop --lib -- api::browser_control_api::tests browser_control_setup_commands_get_the_consent_budget device_rpc_timeout_is_bounded — 5 passed(含总预算小于 Host 限制、回退预算有界、预算耗尽的明确失败)。
  • Services integrations remote_connect::realtime_client::tests — 2 passed(旧默认 deadline/payload、新的 185 秒 payload)。
  • cargo check --locked -p openbitfun-services-integrations --no-default-features --features browser-control — passed。
  • cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,tools-browser-web,tools-computer-use,git --lib browser_control:: — 49 passed,1 ignored。
  • 同一 Core feature 集,filter control_hub — 58 passed,1 ignored。
  • TAURI_CONFIG='{"bundle":{"resources":[],"externalBin":[]}}' cargo test --locked -p openbitfun-desktop --lib -- browser_control_setup_commands_get_the_consent_budget device_rpc_timeout_is_bounded_for_peer_requests — 2 passed。该配置仅免除单测构建中的打包资源要求,不是打包验证。首次共享其他 PR 的 target 目录时编译失败;使用本工作树独立 target 后通过,未通过修改产品代码绕过。
  • corepack pnpm --dir src/web-ui run test:run src/app/scenes/settings/pages/shared/RuntimeSettings.test.tsx src/infrastructure/api/adapters/peer-device-adapter.test.ts — 104 passed。
  • corepack pnpm run check:web — passed。
  • corepack pnpm run fmt:rs、git diff --check — passed。
  • corepack pnpm run check:core-boundaries — 在同一提交的外部 detached worktree 中通过,避免嵌套 Claude worktree 的 Cargo metadata 工作区发现问题。首次检查指出新增 rt 未登记;补齐精确 owner contract 后通过。
  • node --test --test-name-pattern='Tokio' scripts/check-core-boundaries.test.mjs — 9 passed。新增 mutation case 已先失败、后通过。

Compatibility and limitations

  • 不改变持久化记录形状;旧 RPC 方法保留默认行为,使用现有 timeoutMs wire 字段。旧 Host 的 120 秒限制仍可能明确超时,不声称旧端自动支持长预算。
  • 未连接真实 Chrome/Edge,也未操作用户浏览器。连接、拒绝和重试使用 loopback mocks;Peer 的预算和 payload 是本地单测,不是双机端到端验证。
  • Remote workspace 的拒绝路径有工具级测试;真实 SSH、Peer Device、mobile/IM remote control、Detached Dispatch 均未实机验证。未改 operation registry 的 browser-control 范围声明。
  • 显式操作时,如两个浏览器共用端口且均不发布可区分的端点,仍可能先出现一次另一个浏览器的提示;产品验证会拒绝错误连接,startup 则直接跳过这个歧义场景。

Generated with OpenBitFun

bobleer and others added 4 commits November 2, 2026 10:24
Chrome 144+ user-approved remote debugging (chrome://inspect) serves no
/json* HTTP endpoints, so discovery returned 404 while only the browser
WebSocket at /devtools/browser works. The Settings UI also aborted setup
after the default 30 s request deadline while the backend was still
waiting up to 60 s for the setting and 90 s for approval, which surfaced
as "Request timeout".

- Probe CDP ports as Http / GuardedNoHttp / Unreachable and fall back to
  ws://127.0.0.1:{port}/devtools/browser for Chrome and Edge when
  DevToolsActivePort is missing; verify the product after connecting.
- Probe Beta/Dev/Canary and Snap/Flatpak user-data directories.
- Retry guarded WebSocket connects only on refused or fast resets, never
  after a stalled handshake that may be showing an approval prompt.
- Return actionable guidance from legacy HTTP callers on a guarded port.
- Give setup commands a 190 s UI deadline and a matching Peer RPC/host
  invoke budget.

Fixes openBitFun#3654
Co-authored-by: OpenBitFun <318544290+bitfun-ai@users.noreply.github.com>
Co-authored-by: OpenBitFun <318544290+bitfun-ai@users.noreply.github.com>
- Match browser processes by exact name (pgrep -x) instead of command-line substrings that also matched crashpad helpers.
- Cache the process-running answer per setup call and consult it only after the port probe and claim check pass.
- Bound the late-404 setup fallback and its approval wait by one overall 170 s deadline, below the 180 s Peer host invoke limit.
@bobleer
bobleer merged commit 6445a31 into openBitFun:main Nov 2, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 浏览器控制无法连接 Chrome 136+ 默认配置文件:/json/version 返回 404,一直 Request timeout

1 participant