Chrome CDP
Lightweight Chrome DevTools Protocol CLI. Connects directly via WebSocket, does not need Puppeteer, and works well with large tab counts.
Prerequisites
- - Chrome (or Chromium, Brave, Edge, Vivaldi) with remote debugging enabled: open
chrome://inspect/#remote-debugging and toggle the switch - Node.js 22+ (uses built-in WebSocket)
- No Python or pip packages are required
- No
npm install step is required - If your browser's
DevToolsActivePort is in a non-standard location, set CDP_PORT_FILE to its full path
Quick setup
- 1. Open Chrome and keep it running.
- Open
chrome://inspect/#remote-debugging. - Turn on remote debugging.
- Keep the browser open while using this skill.
- Run
{baseDir}/scripts/cdp.mjs list to confirm that tabs are visible.
On first access to a tab, Chrome may ask the user to approve debugging access.
Installation
- - Recommended: INLINECODE6
- Manual: place this skill directory in your OpenClaw workspace
skills/ folder - This skill does not require
npm install, Python, or pip packages
Safety
This skill can inspect and control a real local browser session. Commands such as eval, evalraw, click, type, and nav are intentionally powerful and may trigger warnings from security scanners.
Only use this skill when the user explicitly wants you to inspect or operate pages they already have open. Assume those tabs may contain sensitive logged-in content.
The skill only works after the user enables Chrome remote debugging. On first access to a tab, Chrome may ask the user to approve debugging access.
Commands
All commands use {baseDir}/scripts/cdp.mjs. The <target> is a unique targetId prefix from list; copy the full prefix shown in the list output (for example 6BE827FA). The CLI rejects ambiguous prefixes.
List open pages
CODEBLOCK0
Take a screenshot
CODEBLOCK1
Captures the viewport only. Scroll first with eval if you need content below the fold. Output includes the page's DPR and coordinate conversion hint (see Coordinates below).
Accessibility tree snapshot
CODEBLOCK2
Evaluate JavaScript
CODEBLOCK3
Watch out: avoid index-based selection (querySelectorAll(...)[i]) across multiple eval calls when the DOM can change between them (e.g. after clicking Ignore, card indices shift). Collect all data in one eval or use stable selectors.
Other commands
CODEBLOCK4
Coordinates
INLINECODE23 saves an image at native resolution: image pixels = CSS pixels × DPR. CDP Input events (clickxy etc.) take CSS pixels.
CODEBLOCK5
INLINECODE25 prints the DPR for the current page. Typical Retina (DPR=2): divide screenshot coords by 2.
Tips
- - Prefer
snap --compact over html for page structure. - Use
type (not eval) to enter text in cross-origin iframes — click/clickxy to focus first, then type. - Chrome shows an "Allow debugging" modal once per tab on first access. A background daemon keeps the session alive so subsequent commands need no further approval. Daemons auto-exit after 20 minutes of inactivity.
Chrome CDP
轻量级Chrome DevTools协议命令行工具。直接通过WebSocket连接,无需Puppeteer,在大量标签页下也能良好运行。
前提条件
- - 已启用远程调试的Chrome(或Chromium、Brave、Edge、Vivaldi):打开 chrome://inspect/#remote-debugging 并切换开关
- Node.js 22+(使用内置WebSocket)
- 无需Python或pip包
- 无需执行 npm install
- 如果浏览器的 DevToolsActivePort 位于非标准位置,请将 CDPPORTFILE 设置为其完整路径
快速设置
- 1. 打开Chrome并保持运行。
- 打开 chrome://inspect/#remote-debugging。
- 开启远程调试。
- 使用此技能时保持浏览器打开。
- 运行 {baseDir}/scripts/cdp.mjs list 确认标签页可见。
首次访问标签页时,Chrome可能会要求用户批准调试访问。
安装
- - 推荐:clawhub install chrome-cdp-skill
- 手动:将此技能目录放置在OpenClaw工作区的 skills/ 文件夹中
- 此技能不需要 npm install、Python或pip包
安全性
此技能可以检查和操控真实的本地浏览器会话。eval、evalraw、click、type 和 nav 等命令功能强大,可能会触发安全扫描器的警告。
仅当用户明确要求你检查或操作他们已打开的页面时,才使用此技能。假设这些标签页可能包含敏感的已登录内容。
此技能仅在用户启用Chrome远程调试后生效。首次访问标签页时,Chrome可能会要求用户批准调试访问。
命令
所有命令使用 {baseDir}/scripts/cdp.mjs。 是来自 list 的唯一targetId前缀;复制 list 输出中显示的完整前缀(例如 6BE827FA)。CLI拒绝模糊的前缀。
列出打开的页面
bash
{baseDir}/scripts/cdp.mjs list
截取屏幕截图
bash
{baseDir}/scripts/cdp.mjs shot [file] # 默认:运行时目录中的 screenshot-.png
仅捕获视口。如果需要折叠下方的内容,请先使用 eval 滚动。输出包含页面的DPR和坐标转换提示(参见下面的坐标部分)。
无障碍树快照
bash
{baseDir}/scripts/cdp.mjs snap
评估JavaScript
bash
{baseDir}/scripts/cdp.mjs eval
注意: 当DOM可能在多次 eval 调用之间发生变化时(例如点击忽略后卡片索引会变化),避免跨多次 eval 调用使用基于索引的选择(querySelectorAll(...)[i])。在单次 eval 中收集所有数据,或使用稳定的选择器。
其他命令
bash
{baseDir}/scripts/cdp.mjs html [selector] # 完整页面或元素HTML
{baseDir}/scripts/cdp.mjs nav # 导航并等待加载完成
{baseDir}/scripts/cdp.mjs net # 资源时间条目
{baseDir}/scripts/cdp.mjs click # 通过CSS选择器点击元素
{baseDir}/scripts/cdp.mjs clickxy # 在CSS像素坐标处点击
{baseDir}/scripts/cdp.mjs type # 在当前焦点处Input.insertText;可在跨源iframe中工作,与eval不同
{baseDir}/scripts/cdp.mjs loadall [ms] # 点击加载更多直到消失(默认每次点击间隔1500ms)
{baseDir}/scripts/cdp.mjs evalraw [json] # 原始CDP命令透传
{baseDir}/scripts/cdp.mjs open [url] # 打开新标签页(每次触发允许提示)
{baseDir}/scripts/cdp.mjs stop [target] # 停止守护进程
坐标
shot 以原生分辨率保存图像:图像像素 = CSS像素 × DPR。CDP输入事件(clickxy 等)使用CSS像素。
CSS px = 截图图像 px / DPR
shot 会打印当前页面的DPR。典型Retina屏幕(DPR=2):截图坐标除以2。
提示
- - 对于页面结构,优先使用 snap --compact 而非 html。
- 在跨源iframe中输入文本时使用 type(而非eval)——先使用 click/clickxy 聚焦,然后使用 type。
- Chrome在首次访问每个标签页时会显示允许调试弹窗。后台守护进程会保持会话活跃,因此后续命令无需再次批准。守护进程在20分钟无活动后自动退出。