@duo121/chrome-cdp
v0.1.0
Published
AI-native CLI for managing Chrome CDP instances, targets, and page actions
Downloads
29
Maintainers
Readme
chrome-cdp
chrome-cdp 是一个面向 AI 的 Chrome DevTools Protocol 命令行工具。
- 命令:
chrome-cdp - 别名:
ccdp - 包名:
@duo121/chrome-cdp - GitHub:
https://github.com/duo121/chrome-cdp
设计目标
这个 CLI 不是给人手工拼 CDP 请求用的,而是给 AI 直接调用:
- 所有命令结果统一输出 JSON
chrome-cdp spec是机器可读合同- 推荐工作流是
list -> targets -> resolve-target -> exact action - 尽量避免让 AI 猜测 tab,或者直接手写底层 CDP 请求
安装
npm install -g @duo121/chrome-cdp本地开发:
npm install核心工作流
chrome-cdp list
chrome-cdp targets --port 9222
chrome-cdp resolve-target --port 9222 --type page
chrome-cdp goto --target <handle> --url https://example.com
chrome-cdp screenshot --target <handle> --out ./shot.png常用命令
chrome-cdp spec
chrome-cdp doctor --port 9222
chrome-cdp list
chrome-cdp launch --port 9222
chrome-cdp targets --port 9222
chrome-cdp new-target --port 9222 --url https://example.com
chrome-cdp activate-target --target <handle>
chrome-cdp close-target --target <handle>
chrome-cdp resolve-target --port 9222 --title-contains github
chrome-cdp goto --target <handle> --url https://example.com
chrome-cdp eval --target <handle> --expr "document.title"
chrome-cdp screenshot --target <handle>
chrome-cdp cookies --target <handle>
chrome-cdp set-cookie --target <handle> --name session --value abc --url https://example.com
chrome-cdp stop --port 9222面向 AI 的输入方式
结构化写入支持 --stdin,避免拼很长的 shell 参数:
printf '%s\n' '[{"name":"theme","value":"dark","domain":"example.com","path":"/"}]' \
| chrome-cdp set-cookie --target <handle> --stdinchrome-cdp spec 就是给 AI 用的稳定机器合同。
测试
npm test
npm run test:live
npm run pack:checknpm test 会跑单元测试和基于 fake CDP server 的集成测试。
npm run test:live 会在本机存在 Chrome 时执行真实端到端测试。
发布
npm version patch
git push origin main --tags
npm publishprepublishOnly 会先执行 npm test,GitHub Actions 也会在 push 和 pull request 时跑 CI。
