Skip to content
Skills Library
Programming · Automation

browser-cdp

/browser-cdp

Use this skill when you need to control a Chrome browser via CDP (Chrome DevTools Protocol) to reuse existing login sessions. Covers: launching Chrome in debug mode, opening URLs, waiting for page load, evaluating JavaScript, taking snapshots, and extracting auth tokens. Trigger phrases: browser automation, CDP, agent-browser, 浏览器操作, 操作浏览器, Chrome CDP, 复用登录态, extract token from browser.

Author
uu201 ↗
Licence
MIT
Last repository change
27.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
1
HTML comments
0
URLs in SKILL.md
2
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • 1 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: scripts/setup-cdp-chrome.js

What it does and when to use it

Use this skill when you need to control a Chrome browser via CDP (Chrome DevTools Protocol) to reuse existing login sessions. Covers: launching Chrome in debug mode, opening URLs, waiting for page load, evaluating JavaScript, taking snapshots, and extracting auth tokens. Trigger phrases: browser automation, CDP, agent-browser, 浏览器操作, 操作浏览器, Chrome CDP, 复用登录态, extract token from browser.

Original author description

Use this skill when you need to control a Chrome browser via CDP (Chrome DevTools Protocol) to reuse existing login sessions. Covers: launching Chrome in debug mode, opening URLs, waiting for page load, evaluating JavaScript, taking snapshots, and extracting auth tokens. Trigger phrases: browser automation, CDP, agent-browser, 浏览器操作, 操作浏览器, Chrome CDP, 复用登录态, extract token from browser.

How it works

  1. 前置条件
  2. 启动流程(skill-mode 强制步骤)
  3. 启动脚本选项
  4. 常用操作
  5. 停止 / 清理
  6. 常见问题
Original SKILL.md headings · 131 lines, 393 words
SKILL.md preview
---
name: browser-cdp
description: "Use this skill when you need to control a Chrome browser via CDP (Chrome DevTools Protocol) to reuse existing login sessions. Covers: launching Chrome in debug mode, opening URLs, waiting for page load, evaluating JavaScript, taking snapshots, and extracting auth tokens. Trigger phrases: browser automation, CDP, agent-browser, 浏览器操作, 操作浏览器, Chrome CDP, 复用登录态, extract token from browser."
metadata:
  openclaw:
    requires:
      bins:
        - agent-browser
    source: https://github.com/worldwonderer/oh-story-claudecode
---

# Browser CDP 操作工具

通过 CDP 协议控制 Chrome,复用已有登录态,执行浏览器自动化操作。

## 前置条件

- macOS / Linux / Windows(实验性),已安装 Google Chrome
- Node.js 12+
- `agent-browser` 已安装:`npm install -g agent-browser`

> ⚠️ **首次启动会 kill 用户的常规 Chrome。** 在启动前必须征求用户同意(见下方"启动流程"),否则用户可能丢失未保存的标签页/草稿。

---

## 启动流程(skill-mode 强制步骤)

**第一步:探测当前状态(无副作用)**

```bash
node {SKILL_DIR}/scripts/setup-cdp-chrome.js 9222 --detect-only
```

输出形如:

```
CDP_STATUS=ready                        # 已就绪,可直接复用
CDP_URL=http://127.0.0.1:9222/json/version
BROWSER=Chrome/148.0.7778.168
```

或:

```
CDP_STATUS=needs-setup
CHROME_RUNNING=yes                      # 用户有 Chrome 在跑,启动会杀掉
CHROME_PID_COUNT=3
```

**第二步:根据探测结果分支**

- `CDP_STATUS=ready` → 直接使用 `agent-browser --cdp 9222 ...`,**不要运行 setup**。
- `CDP_STATUS=needs-setup` 且 `CHROME_RUNNING=no` → 安全启动:
  ```bash
  node {SKILL_DIR}/scripts/setup-cdp-chrome.js 9222 --yes
  ```
- `CDP_STATUS=needs-setup` 且 `CHROME_RUNNING=yes` → **先用 AskUserQuestion 工具向用户确认**:告知会杀掉 N 个 Chrome 进程、可能丢失未保存工作;用户同意后再带 `--yes` 启动;用户拒绝则放弃这次自动化。

**为什么不能直接 `--yes`:** 脚本在非 TTY(即 skill 模式 / Bash 工具)下,如果检测到 Chrome 在跑而没有 `--yes`,会以退出码 3 报 `NEEDS_CONSENT: ...` 并中止,**不会**静默杀进程。这是有意的兜底——但 skill 流程仍应先问用户,而不是看到 3 就盲传 `--yes`。

---

## 启动脚本选项

| 选项 | 说明 |
|------|------|
| `--detect-only` | 只探测,不修改任何状态(skill 用) |
| `--yes` | 已征得同意,跳过交互提示 |
| `--reset` | 启动前清空 `~/chrome-debug-profile`(登录失效时用) |
| `--profile <name>` | 使用非 Default 的 Chrome profile(如 `"Profile 1"`) |
| `--dry-run` | 打印将执行的步骤,不执行 |

退出码:`0` 成功 / `1` 通用错误 / `2` 用户拒绝(TTY)/ `3` 需同意但缺 `--yes`。

---

## 常用操作

### 打开页面并等待加载

```bash
agent-browser --cdp 9222 open "<URL>"
agent-browser --cdp 9222 wait 3000
```

### 提取页面文本

```bash
agent-browser --cdp 9222 eval 'document.body.innerText.substring(0, 8000)'
```

### 提取 Auth Token

```bash
agent-browser --cdp 9222 eval 'localStorage.getItem("token") || document.cookie'
```

### 复杂 JS(含引号 / `$` / 反引号)

shell 转义容易出错,用以下两种方式之一:

```bash
# 1) base64 包裹
agent-browser --cdp 9222 eval -b "$(echo -n "document.querySelectorAll('a').length" | base64)"

# 2) heredoc + --stdin
cat <<'EOF' | agent-browser --cdp 9222 eval --stdin
const links = document.querySelectorAll('a');
links.length;
EOF
```

### 页面交互(snapshot 拿元素引用)

```bash
agent-browser --cdp 9222 snapshot -i        # 仅交互元素
agent-browser --cdp 9222 click "<CSS or @e1>"
agent-browser --cdp 9222 type "<sel>" "<text>"
```

---

## 停止 / 清理

- 关掉 debug Chrome 窗口即可(或 `pkill -9 -x 'Google Chrome'` / `taskkill /F /IM chrome.exe`)。
- 登录态失效:`node {SKILL_DIR}/scripts/setup-cdp-chrome.js 9222 --reset --yes`(注意 `--yes` 同样需要先问用户)。

---

## 常见问题

| 问题 | 解决方案 |
|------|----------|
| `NEEDS_CONSENT` + 退出码 3 | 用 AskUserQuestion 询问用户是否允许杀掉 Chrome,同意后加 `--yes` 重跑 |
| CDP 端口未监听 | `--detect-only` 再确认;端口被占用则换端口 |
| 页面跳转到登录页 | `snapshot -i` 找登录按钮并操作 |
| `eval` 返回 `null` | 检查 localStorage key 名;含引号的 JS 用 `eval -b` 或 `--stdin` |
| 登录态过期 | `setup-cdp-chrome.js 9222 --reset --yes` 重新拷贝 |
| 有多个 Chrome profile | `--profile "Profile 1"` 指定 |
| Chrome 不会启动(30s 超时) | 试 `--reset`;检查端口冲突;查看 `~/chrome-debug-profile/` 是否损坏 |
Files in this package (2)
  • SKILL.md 5 KB
  • scripts/setup-cdp-chrome.js 18 KB

Versions

RepositoryScoreLicence
This page · uu201/character-arc100MIT
worldwonderer/oh-story-claudecode100MIT
zenstory-ai/oh-story-claudecode100MIT
qin1473692580-ux/oh-story-claudecode100MIT
heriki/oh-story-codex100MIT
duiniwukenaihe/novel-assistant-skill100MIT

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 40bbffa9f245 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100browser-use
    统一处理浏览器使用任务,支持可见浏览器 CDP 直连、专用 headless CDP、agent-browser。Use when the user asks to browse websites, interact with pages, fill forms, capture screenshots, reuse an existing Chrome/Chromium/Edge login session, work with an already-open browser/sidebar browser, access…
  • 95browser
    Direct browser control via CDP. Use when the user wants to automate, scrape, test, or interact with web pages. Connects to the user's already-running Chrome.
  • 95cdp
    Drive Chrome via the DevTools Protocol from JavaScript. Run JS snippets through the `browser-harness-js` CLI — it auto-spawns a long-lived bun HTTP server holding a fully-typed CDP `Session`, and every call (`browser-harness-js 'await session.Page.navigate(...)'`) executes…
  • 100operating-cdp-cli
    Drives a live browser with the repo's cdp CLI — attaching to a running Chrome/Brave, navigating, clicking, evaluating JavaScript, extracting page state, and running the screenshot-first observe-act-verify loop over cdp --mcp. Use when the task means operating a browser right now…
  • 100browser
    This skill should be used for browser automation tasks using Chrome DevTools Protocol (CDP). Triggers when users need to launch Chrome with remote debugging, navigate pages, execute JavaScript in browser context, capture screenshots, or interactively select DOM elements. No MCP server required.
  • 100verify-chrome-cdp-ex
    Verify chrome-cdp-ex (CLI and MCP driving a real Chrome). Use when proving a fix, or when a reviewer re-runs the user path on a PR head.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.