“当日嫌它的唱法做作,现在听起来竟然很生动,可能是时光让耳朵变得宽容。——《幻听》”
01
—
操作步骤
1、输入提示词,可以看到Zcode无法调用断点调试相关api
https://cdn-zcode.z.ai/zcode/electron/releases/3.7.3/windows-x64/ZCode-3.7.3-win-x64.exe访问 baidu.com,然后 evaluate("1+1")、enableDebugger、events、openDevTools
2、查看调用轨迹日志,调用browser-use skill
C:\Users\Administrator\.zcode\cli\rollout\
3、查看运行日志里的 tool 顺序
C:\Users\Administrator\.zcode\cli\logSkill → mcp__node_repl__js(setupBrowserRuntime)→ mcp__node_repl__js(getForUrl+documentation)→ mcp__node_repl__js(tabs.new+goto)→ mcp__node_repl__js(playwright.evaluate)

4、查看browser-use提供的API,没有断点调试相关接口
C:\Users\Administrator\.zcode\cli\plugins\cache\zcode-plugins-official\browser-use\0.2.1\docs\api.json
5、主机日志确认IAB已经attach CDP,只是没有提供API调用
C:\Users\Administrator\.zcode\v2\logs\
6、模型如何驱动浏览器
C:\Users\Administrator\.zcode\cli\plugins\cache\zcode-plugins-official\browser-use\0.2.1\scripts\browser-client.mjs模型→ 工具 mcp__node_repl__js→ 执行 JS:import browser-client,使用 agent.browsers 与 tab 上的方法→ 客户端把操作收成 command 对象,经 transport.execute(browserId, generation, command) 发出→ Node REPL 浏览器 Broker(命名管道或 socket,zcode.cjs 侧)收到请求→ Broker 调用 browserControlPort.execute,把 command 交给桌面浏览器控制口→ Host 进程 IPC:interaction/browserExecute→ Main 进程:校验消息后执行 runBrowserCommandOnView,再进入 BrowserUse.execute(command)→ Main 根据 command.method 选择分支处理(出厂已有例如 navigate、playwright、getState、screenshot、close;没有 cdp 分支,所以 enableDebugger 一类调不到)「command.method 分支」说明:command 是一个 JSON 对象,里面有字段 method。Main 里类似 if (method === "navigate") 做导航,if (method === "playwright") 做 Playwright 动作。出厂枚举到 list 为止,没有 method === "cdp",模型再怎么调断点相关名字也不会进调试分支。

7、出厂执行桥:没有 method=cdp
C:\Users\Administrator\.zcode\report\local-backups-373\app.asar.bak-unpacked\out\main\index.js
8、补丁执行桥:增加 method=cdp
C:\Users\Administrator\.zcode\report\files\asar-extracted\out\main\index.js
9、出厂 Main schema
C:\Users\Administrator\.zcode\report\local-backups-373\app.asar.bak-unpacked\out\main\chunk-PWHDRJIQ.js
10、补丁 Main schema:加上 cdp
C:\Users\Administrator\.zcode\report\files\asar-extracted\out\main\chunk-PWHDRJIQ.js
11、补丁 Host schema:加上 cdp
C:\Users\Administrator\.zcode\report\files\asar-extracted\out\host\chunk-VMEOUWWD.js
12、补丁 Broker:g.enum 加 cdp
C:\Users\Administrator\.zcode\report\files\glm\zcode.cjs
13、补丁 Broker:parse 前先取请求 raw.id,避免错误回包 id 错乱
C:\Users\Administrator\.zcode\report\files\glm\zcode.cjs
14、补丁模型侧:模型侧暴露 tab.cdp 入口
C:\Users\Administrator\.zcode\report\files\plugin\scripts\browser-client.mjs
15、补丁文档:api.json 声明 enableDebugger
C:\Users\Administrator\.zcode\report\files\plugin\docs\api.json
16、效果如下
打开 https://www.baidu.com。用 tab.cdp.evaluate("1+1")、tab.cdp.enableDebugger()、tab.cdp.events({limit:50})、tab.openDevTools() 依次调用。然后控制台执行(function() {var stringify = JSON.stringify;JSON.stringify = function(params) {console.log("Hook JSON.stringify ——> ", params);debugger;return stringify(params);}})();

17、替换清单
关闭进程Get-Process -Name ZCode -ErrorAction SilentlyContinue | Stop-Process -Forcehttps://github.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/blob/main/files/glm/zcode.cjs.gz(下载后解压为 zcode.cjs,见同目录 README)→ D:\ZCode\resources\glm\zcode.cjshttps://github.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/blob/main/files/plugin/scripts/browser-client.mjs→ C:\Users\Administrator\.zcode\cli\plugins\cache\zcode-plugins-official\browser-use\0.2.1\scripts\browser-client.mjs→ D:\ZCode\resources\glm\packages\browser-use-plugin\scripts\browser-client.mjshttps://github.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/blob/main/files/plugin/docs/api.json→ C:\Users\Administrator\.zcode\cli\plugins\cache\zcode-plugins-official\browser-use\0.2.1\docs\api.json→ D:\ZCode\resources\glm\packages\browser-use-plugin\docs\api.jsonhttps://github.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/tree/main/files/asar-patches(解包本机官方 app.asar 后覆盖下列 3 个文件,再 asar pack)out/main/index.jsout/main/chunk-PWHDRJIQ.jsout/host/chunk-VMEOUWWD.js→ 打包结果覆盖 D:\ZCode\resources\app.asarraw(可直接下载):https://raw.githubusercontent.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/main/files/plugin/scripts/browser-client.mjshttps://raw.githubusercontent.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/main/files/plugin/docs/api.jsonhttps://raw.githubusercontent.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3/main/files/glm/zcode.cjs.gz打包 asar 步骤见仓库 README:https://github.com/Almost-Zhangsan/zcode-cdp-patch-3.7.3

夜雨聆风