feat: 兼容 Chrome 136+ DevTools Remote Debugging 的 CDP 连接(WebSocket/TCP fallback)#186
Open
aquaqu-v246 wants to merge 1 commit intoepiral:mainfrom
Open
feat: 兼容 Chrome 136+ DevTools Remote Debugging 的 CDP 连接(WebSocket/TCP fallback)#186aquaqu-v246 wants to merge 1 commit intoepiral:mainfrom
aquaqu-v246 wants to merge 1 commit intoepiral:mainfrom
Conversation
Chrome 136+ disables HTTP discovery endpoints (/json/version) for default user profiles while WebSocket CDP endpoints remain functional. This affects browsers like Comet that enable remote debugging via DevTools settings rather than --remote-debugging-port flag. Changes: - cli/cdp-discovery.ts: canConnect() falls back to TCP port check when HTTP /json/version returns 404 - daemon/index.ts: extract canConnectCdp() with same TCP fallback, used by discoverCdpPort() - daemon/cdp-connection.ts: doConnect() constructs WebSocket URL directly (ws://host:port/devtools/browser) when HTTP discovery fails TCP port checks (net.connect) are used instead of WebSocket probes in discovery functions to avoid triggering browser CDP permission prompts. Only the actual persistent connection in doConnect() uses WebSocket, resulting in a single permission prompt per daemon session.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
从 Chrome 136 版本开始,Chromium 出于安全考虑(防止恶意软件通过 CDP 窃取用户 Cookie/凭据),对默认 user profile 禁用了 HTTP 发现端点(
/json/version、/json/list),这些端点直接返回 404。这导致
bb-browser无法连接那些通过浏览器内置 DevTools 设置(chrome://inspect/#remote-debugging)开启远程调试的浏览器(如 Comet 浏览器等),因为当前代码依赖/json/version来判断 CDP 端口是否可用。核心发现
虽然 HTTP 发现端点被禁用了,但 WebSocket CDP 端点(
ws://host:port/devtools/browser)仍然完全可用,且支持全部 CDP 1.3 协议功能。实际测试结果:
GET /json/versionws://host:port/devtools/browserBrowser.getVersionTarget.getTargets改动内容
1. CLI 端口探测:
canConnect()(cdp-discovery.ts)fetch("/json/version")判断端口可用性net.connect)2. Daemon 端口探测:
discoverCdpPort()(index.ts)canConnectCdp()公共函数,复用 HTTP + TCP 双重检测逻辑3. Daemon WebSocket 连接:
doConnect()(cdp-connection.ts)/json/version获取webSocketDebuggerUrlws://host:port/devtools/browser连接关于权限弹框
Chrome 的 Remote Debugging 在首次 WebSocket 连接时会弹出用户确认框,这是安全机制,无法绕过。
本次改动通过将探测阶段的 WebSocket 改为 TCP,将弹框从 3 次减少到 1 次(仅在 daemon 建立真正的持久连接时弹出)。daemon 存活期间复用同一个连接,不会再弹。
测试结果
open、get title、get url、close全功能正常--remote-debugging-port工作流:无影响(优先走 HTTP 路径,仅在 HTTP 失败时 fallback)