cdp-browser
CLI for Chrome/Chromium at localhost:9222. Inspect tabs, take screenshots, navigate, scroll, post to X, or run JS in a persistent browser session.
Repo: https://github.com/gostlightai/cdp-browser
Prerequisites: Chromium running with --remote-debugging-port=9222. Docker Compose or a local Chrome with remote debugging enabled.
Commands
Run from the skill dir (bin/ scripts):
| Command | Description |
|---|
| INLINECODE2 | List all tabs (JSON from CDP) |
| INLINECODE3 |
Same as status |
|
new <url> | Open new tab |
|
goto <tabId> <url> | Navigate tab to URL |
|
snapshot <tabId> | Full-page screenshot (PNG) |
|
close-popup <tabId> | Dismiss dialogs/modals |
|
scroll <tabId> <px\|sel> [down\|up] | Scroll by pixels or selector |
|
query <tabId> getUrl | Return current page URL |
|
query <tabId> getText [selector] | Return element text (or body) |
|
query <tabId> getHtml [selector] | Return element HTML (or body) |
|
tweet-draft <tabId> "text" | Fill compose box only; does NOT post |
|
tweet-post <tabId> --confirm "text" | Post tweet (requires
--confirm as second arg) |
|
tweet <tabId> "text" | Alias for tweet-draft (fills compose only) |
Tweet flow
- - tweet-draft (default): Fills the compose box; user reviews in browser and posts manually.
- tweet-post: Requires
--confirm as second arg (strict). Use when user explicitly approves ("go ahead", "post it", or Telegram confirm button). - Optional Telegram confirm: When
tweet.confirmButton is enabled in config, the agent can run tweet-draft --save-pending to write pending state, then send a message with an inline "Confirm Post" button. On confirm, the agent runs tweet-post --confirm.
Config (required for Telegram confirm button)
The Telegram "Confirm Post" button only works if config exists. Copy the example and place it in your workspace:
CODEBLOCK0
Location: ~/.openclaw/workspace/.cdp-browser.json (or $OPENCLAW_WORKSPACE/.cdp-browser.json)
| Key | Default | Description |
|---|
| INLINECODE22 | INLINECODE23 | When true, agent sends draft with inline "Confirm Post" button in Telegram. User clicks to approve or says "go ahead". |
Without this config, the agent uses plain tweet-draft (no button); user confirms via text only.
Telegram confirm button (agent instructions)
When tweet.confirmButton is true (config present) and you are in a Telegram session:
- 1. Draft: Run
tweet-draft --save-pending <tabId> "text" from the skill dir. This fills the compose box and writes ~/.openclaw/workspace/.cdp-browser/pending-tweet.json. - Send with button: Run from the skill dir:
./scripts/send-tweet-confirm.sh <chat_id> "<tweet_text>"
Or use
openclaw message send directly with
--buttons '[[{"text":"Confirm Post","callback_data":"cdp:tweet:confirm"}]]'. Use the current session's reply target as
<chat_id>.
- 3. On confirm: When the user clicks the button, OpenClaw delivers
callback_data: cdp:tweet:confirm. Or the user says "go ahead"/"post it". Treat either as approval. Then:
- Read
~/.openclaw/workspace/.cdp-browser/pending-tweet.json for
text and
tabId
- Run
tweet-post <tabId> --confirm "<text>"
- Edit or delete the message with the button (optional)
- Delete the pending file
Scripts
- - cdp.js — Fetch-only wrapper for CDP HTTP API (
/json, /json/list, /json/new); no shell. - pw.js — Playwright connect to browser; runs snapshot/goto/scroll/query/tweet-draft/tweet-post. Compose launcher: SideNavNewTweetButton, /compose/post, Post only (avoids reply buttons). Post button: tweetButton, tweetButtonInline.
Security
See SECURITY.md for mitigations and operational notes.
cdp-browser
用于本地localhost:9222上Chrome/Chromium的CLI工具。可在持久化浏览器会话中检查标签页、截图、导航、滚动、发布到X或运行JavaScript。
仓库地址: https://github.com/gostlightai/cdp-browser
前置条件: 使用--remote-debugging-port=9222参数运行的Chromium。Docker Compose或启用了远程调试的本地Chrome。
命令
从技能目录(bin/脚本)运行:
| 命令 | 描述 |
|---|
| status | 列出所有标签页(来自CDP的JSON) |
| tabs |
与status相同 |
| new
| 打开新标签页 |
| goto | 将标签页导航至URL |
| snapshot | 全页面截图(PNG格式) |
| close-popup | 关闭对话框/模态框 |
| scroll [down\|up] | 按像素或选择器滚动 |
| query getUrl | 返回当前页面URL |
| query getText [selector] | 返回元素文本(或body) |
| query getHtml [selector] | 返回元素HTML(或body) |
| tweet-draft text | 仅填充撰写框;不发布 |
| tweet-post --confirm text | 发布推文(需要--confirm作为第二个参数) |
| tweet text | tweet-draft的别名(仅填充撰写框) |
推文流程
- - tweet-draft(默认):填充撰写框;用户在浏览器中审核并手动发布。
- tweet-post:需要--confirm作为第二个参数(严格模式)。当用户明确批准时使用(go ahead、post it或Telegram确认按钮)。
- 可选的Telegram确认: 当配置中启用了tweet.confirmButton时,代理可以运行tweet-draft --save-pending来写入待处理状态,然后发送带有内联确认发布按钮的消息。确认后,代理运行tweet-post --confirm。
配置(Telegram确认按钮必需)
Telegram确认发布按钮仅在存在配置时生效。复制示例并将其放置在工作区中:
bash
从技能目录(例如 ~/.openclaw/workspace/skills/cdp-browser):
cp .cdp-browser.json.example ~/.openclaw/workspace/.cdp-browser.json
位置: ~/.openclaw/workspace/.cdp-browser.json(或$OPENCLAW_WORKSPACE/.cdp-browser.json)
| 键 | 默认值 | 描述 |
|---|
| tweet.confirmButton | false | 当为true时,代理在Telegram中发送带有内联确认发布按钮的草稿。用户点击批准或说go ahead。 |
没有此配置时,代理使用普通的tweet-draft(无按钮);用户仅通过文本确认。
Telegram确认按钮(代理指令)
当tweet.confirmButton为true(配置存在)且您在Telegram会话中时:
- 1. 草稿: 从技能目录运行tweet-draft --save-pending text。这会填充撰写框并写入~/.openclaw/workspace/.cdp-browser/pending-tweet.json。
- 带按钮发送: 从技能目录运行:
bash
./scripts/send-tweet-confirm.sh id> text>
或直接使用openclaw message send,带上--buttons [[{text:确认发布,callbackdata:cdp:tweet:confirm}]]。使用当前会话的回复目标作为id>。
- 3. 确认时: 当用户点击按钮时,OpenClaw传递callback_data: cdp:tweet:confirm。或者用户说go ahead/post it。将任一情况视为批准。然后:
- 读取~/.openclaw/workspace/.cdp-browser/pending-tweet.json获取text和tabId
- 运行tweet-post --confirm
- 编辑或删除带按钮的消息(可选)
- 删除待处理文件
脚本
- - cdp.js — 仅用于CDP HTTP API(/json、/json/list、/json/new)的获取封装;无shell。
- pw.js — Playwright连接浏览器;执行snapshot/goto/scroll/query/tweet-draft/tweet-post。撰写启动器:SideNavNewTweetButton、/compose/post、Post only(避免回复按钮)。发布按钮:tweetButton、tweetButtonInline。
安全性
有关缓解措施和操作说明,请参阅SECURITY.md。