
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.
- Installs
- 16.9K
- Last 24h
- +98
- Trending rank
- #2012
- Security
- Warn
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/zenstory-ai/oh-story-claudecode --skill browser-cdp- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads browser-cdp automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
Security audits
Independent scans of the skill's instructions and bundled files.
SKILL.md
The instructions your agent reads when the skill is triggered.
Browser CDP 操作工具
通过 CDP(Chrome DevTools Protocol)连接 Chrome,复用登录态并执行浏览器操作。
前置条件
- macOS / Linux / Windows(实验性),已安装并使用过 Google Chrome,来源 profile 已存在
- Node.js 20+
agent-browser已安装:npm install -g agent-browser
启动或重建时,若需结束 Chrome 进程,先按下方流程征得同意;未保存的标签页或草稿可能丢失。
启动流程(每次都按这个顺序)
下文 {SKILL_DIR} 指本 skill(browser-cdp)的目录。
第一步:探测当前状态(无副作用)
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=needs-setup且CHROME_INSTALLED=no→ 本机没找到 Chrome,告诉用户先安装并用它登录一次需要的网站,不要运行 setup。CDP_STATUS=ready且本次只需连接 → 直接使用agent-browser --cdp 9222 ...,不要运行 setup。- 明确请求
--reset/--profile→ 即使 ready 也走重建,按下方「需要结束 Chrome 时」处理。 CDP_STATUS=needs-setup且CHROME_RUNNING=no→ 安全启动:node {SKILL_DIR}/scripts/setup-cdp-chrome.js 9222 --yesCDP_STATUS=needs-setup且CHROME_RUNNING=yes→ 按下方「需要结束 Chrome 时」处理。
需要结束 Chrome 时(同意流程):凡是会结束正在运行的 Chrome 的命令(Chrome 在运行时启动、--reset、显式 --profile),都按这三步走:
- 带上原定选项加
--dry-run跑一次,看会结束几个 Chrome 进程; - 告诉用户会结束 N 个 Chrome 进程、未保存的标签页或草稿可能丢失,问是否继续;
- 用户同意后,去掉
--dry-run、加--yes重跑;用户拒绝就放弃这次自动化。
非 TTY 调用中,Chrome 在运行且未传 --yes 时,脚本以退出码 3 报 NEEDS_CONSENT: ... 并中止。取得同意后再重跑,不自动补 --yes。
换端口:9222 被别的程序占用时可以换一个端口(如 9333),之后所有 agent-browser --cdp 命令用同一个端口,扫榜脚本加 --port 9333,查资料助手传 cdp_port: 9333。
启动脚本选项
| 选项 | 说明 |
|---|---|
--detect-only | 只探测,不修改任何状态 |
--yes | 已征得同意,跳过交互提示 |
--reset | 启动前清空 ~/chrome-debug-profile(登录失效时用) |
--profile <name> | 指定来源 profile(默认 Default,如 "Profile 1");显式传入即重建 |
--dry-run | 打印将执行的步骤,不执行 |
退出码:0 成功 / 1 通用错误 / 2 用户拒绝(TTY)/ 3 需同意但缺 --yes。
常用操作
打开页面并等待加载
agent-browser --cdp 9222 open "<URL>"
agent-browser --cdp 9222 wait 3000
提取页面文本
agent-browser --cdp 9222 eval 'document.body.innerText.substring(0, 8000)'
提取 Auth Token
示例读取 localStorage 的 token 项或 JavaScript 可读的 Cookie;实际存放位置按站点确认。
agent-browser --cdp 9222 eval 'localStorage.getItem("token") || document.cookie'
复杂 JS(含引号 / $ / 反引号)
用 base64 或标准输入传入脚本,避免 shell 转义错误:
# 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 拿元素引用)
agent-browser --cdp 9222 snapshot -i # 仅交互元素
agent-browser --cdp 9222 click "<CSS or @e1>"
agent-browser --cdp 9222 type "<sel>" "<text>"
停止 / 清理
- 关掉 debug Chrome 窗口即可。若窗口无响应,先按
--user-data-dir核验出 debug 实例的 PID 再只结束它:- macOS / Linux:
pgrep -af chrome-debug-profile - Windows(PowerShell):
Get-CimInstance Win32_Process | Where-Object CommandLine -like '*chrome-debug-profile*' | Select-Object ProcessId,CommandLine;没有 PowerShell 的旧系统才用wmic process get ProcessId,CommandLine | findstr chrome-debug-profile核验 PID 后用kill -9 {PID}/taskkill /F /PID {PID},无法核验则停止。手工清理不得按 Chrome 可执行文件名批量结束进程;启动脚本仍走上述同意流程。
- macOS / Linux:
- 登录态失效:用
node {SKILL_DIR}/scripts/setup-cdp-chrome.js 9222 --reset重新复制来源 profile,按上方「需要结束 Chrome 时」先 dry-run、征得同意再加--yes。
长命令加超时
在前台执行耗时的 CDP 命令时,为页面加载和批量采集设置超时,避免单次调用长时间占住会话。
超时包装
Windows 用 PowerShell Job 设置超时:
$job = Start-Job { agent-browser --cdp 9222 eval "window.location.replace('https://www.qidian.com/rank/')" }
Wait-Job $job -Timeout 30 | Out-Null
if ($job.State -eq 'Running') { Stop-Job $job; Write-Output "⏱ CDP 操作超时(30s),请重试或手动打断" }
else { Receive-Job $job }
Remove-Job $job -Force
macOS / Linux 有 timeout 时:
timeout 30 agent-browser --cdp 9222 eval "window.location.replace('https://www.qidian.com/rank/')" || echo "⏱ CDP 操作超时(30s),请重试或手动打断"
已知限制
| 场景 | 风险 | 缓解 |
|---|---|---|
| 页面加载超时 | eval 命令等待永不返回 | 设置 30s 超时,超时后重试 |
| 大批量数据抓取 | 多页翻页时累计等待过长 | 每页独立超时,失败后从断点继续 |
| Chrome 进程僵死 | CDP 连接断开但进程未退出 | 先核验 debug profile 对应 PID,只结束该 debug 实例后重连;不得连带普通 Chrome |
| 网络波动 | 请求挂起无超时 | 超时后自动重试一次 |
持续卡死时,请用户在宿主里手动打断(如 OpenCode、Claude Code 按 ESC)。
常见问题
| 问题 | 解决方案 |
|---|---|
NEEDS_CONSENT + 退出码 3 | 按「需要结束 Chrome 时」:先 dry-run 说清会结束几个进程,同意后加 --yes 重跑 |
CHROME_INSTALLED=no 或来源 profile 不存在 | 安装并使用 Chrome 一次;已有其他 profile 时用 --profile 指定(会重建,按同意流程) |
| CDP 端口未监听 | --detect-only 再确认;端口被占用就换端口,下游命令一起改(见「换端口」) |
| 页面跳转到登录页 | snapshot -i 找登录按钮并操作 |
eval 返回 null | 检查 localStorage key 名;含引号的 JS 用 eval -b 或 --stdin |
| 登录态过期 | setup-cdp-chrome.js 9222 --reset,按同意流程先 dry-run、同意后加 --yes |
| 有多个 Chrome profile | --profile "Profile 1" 指定;显式传 --profile 会重建,按同意流程 |
| Chrome 不会启动(30s 超时) | 检查端口冲突;查看 ~/chrome-debug-profile/ 是否损坏;仍不行再按同意流程试 --reset |
FAQ
What does the browser-cdp skill do?
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 do I install browser-cdp?
Run npx skills add https://github.com/zenstory-ai/oh-story-claudecode --skill browser-cdp in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/browser-cdp/ (personal) or .claude/skills/browser-cdp/ (project).
Which AI agents can use browser-cdp?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is browser-cdp safe to install?
Security partners have reviewed it: Gen Agent Trust Hub flagged items to review; Socket flagged items to review; Snyk flagged items to review. As with any skill, read the SKILL.md and bundled scripts before installing.
Who maintains browser-cdp?
It is published by zenstory-ai in zenstory-ai/oh-story-claudecode. It has 16,884 recorded installs.
More from zenstory-ai/oh-story-claudecode
story-long-write
zenstory-ai/oh-story-claudecode
长篇网文规划与写作。支持只讨论结构、只写大纲或指定细纲,明确要求正文后再写章节。触发方式:/story-long-write、/写长篇、「帮我开书」「定设定」「出卷纲」「规划剧情」「写大纲」「补细纲」「日更」「续写」「继续写」「修改第X章」「回炉」「重写第X章」。
story-deslop
zenstory-ai/oh-story-claudecode
网文去AI味。从表达、叙事用笔、故事因果三层诊断并修复文本,保留作者文风与已定剧情。触发方式:/story-deslop、/去AI味、「去AI味」「这篇太AI了」「网文去AI味」。
story-long-analyze
zenstory-ai/oh-story-claudecode
长篇网文拆文。保留黄金三章、逐章摘要、剧情、情绪、节奏、角色、设定和文风接口,以连续章节块完成因果、双时间线、关系与三维节奏分析;兼容旧成果直接使用、按需增强和断点续跑。含可选三层灵感库管道(灵感库、跨书灵感聚合、更新灵感库)。触发方式:/story-long-analyze、/长篇拆文、「帮我拆这本书」「拆这本书」「分析黄金三章」「深度拆解」「完整拆解」或提供小说文本文件路径。
story-short-write
zenstory-ai/oh-story-claudecode
短篇网文写作。辅助短篇小说创作,从构思到成稿,聚焦情绪拉扯与节奏把控。触发方式:/story-short-write、/写短篇、「帮我写一篇短篇」「写个盐言故事」。
story-long-scan
zenstory-ai/oh-story-claudecode
长篇网文扫榜。分析起点、番茄、晋江、七猫等平台排行榜与新书数据,提炼市场趋势与热门题材。触发方式:/story-long-scan、/长篇扫榜、「长篇什么火」「起点排行」「扫七猫新书」。
story-short-analyze
zenstory-ai/oh-story-claudecode
短篇网文拆文。拆解爆款短篇小说(番茄短篇 / 故事会 / 知乎盐言 / 追妻 / 世情 / 重生 / 虐渣等通俗题材)的故事核、结构、情感线、反转设计、写作手法、共鸣层次。单一全量拆解管道:跑完 Stage 2-6 产出完整拆文报告,落盘到 拆文库/{书名}/,下游 story-short-write 同时读拆文报告 + 情节节点 + 写作手法 + 原文 + meta.json 写下一篇。触发方式:/story-short-analyze、/短篇拆文、「拆短篇」「拆这篇短文」「短篇拆文」「精细拆解短篇」「8000 字短篇拆解」「番茄短篇拆文」「故事会拆解」「盐言故事拆解」「分析这篇短篇」——均进入同一管道。
Popular productivity & automation skills
agent-browser
vercel-labs/agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.
lark-doc
open.feishu.cn
飞书云文档(Docx / Wiki)内容操作:读取、创建、编辑文档,插入或下载图片附件,以及操作思维笔记。用户提供文档 URL/token(包括 doubao.com 的 /docx/、/wiki/)时使用;按 URL 路径/token 而非域名路由;/page/ 是妙搭应用,非飞书云文档。文档内嵌资源按读取参考中的统一规则分流。独立评论操作走 lark-drive;随正文读取评论使用 docs +fetch。表格或 Base 内部数据操作不在本 skill。
lark-base
open.feishu.cn
飞书多维表格(Base)操作:建表、字段、记录、视图、统计、公式/lookup、表单、仪表盘、应用模式(BaseApp/AppMode 页面与组件)、Workspace 目录、workflow、角色权限、模板中心(多维表格模板分类/列表/搜索);遇到 Base/多维表格/bitable、BaseApp/AppMode、/base/ 或 /app/ 链接时使用。BaseApp 不走 lark-apps;文件导入/导出转 lark-drive,认证/授权转 lark-shared。
lark-drive
open.feishu.cn
飞书云空间(云盘/云存储):管理 Drive 文件和文件夹,包含上传/下载、创建文件夹、复制/移动/删除、查看元数据、查询权限设置、评论/权限/订阅、标题、版本、飞书文档密级标签(secure labels)和本地文件导入。用户需要整理云盘目录、处理云空间资源 URL/token、判断链接类型/真实 token/标题,或导入 Word/Markdown/Excel/CSV/PPTX/.base 为 docx/sheet/bitable/slides 时使用;doubao.com 云空间 URL/token 也按资源路径和 token 路由,不回退 WebFetch。不负责:文档内容编辑(走 lark-doc)、表格/Base 表内数据操作(走 lark-sheets/lark-base)、知识空间节点/成员管理(走 lark-wiki)、原生 Markdown 文件读写/patch/diff(走 lark-markdown)。
lark-shared
open.feishu.cn
Use for lark-cli setup/auth tasks: auth login/status/logout, user vs bot identity, business-domain permissions (--domain, including all/docs/drive), missing scopes, revoking authorization, or handling notice JSON.
lark-im
open.feishu.cn
飞书即时通讯:收发消息和管理群聊。发送和回复消息、搜索聊天记录、管理群聊成员、上传下载图片和文件、管理表情回复、发送应用内/短信/电话加急、发送和处理交互卡片(Interactive Card)、监听卡片按钮回调(card.action.trigger)。当用户需要发消息、查看或搜索聊天记录、下载聊天中的文件、查看群成员、搜索群、创建群聊或话题群、管理标记数据、管理 Feed 置顶(添加/移除/查询置顶会话)、管理标签数据、处理卡片回调时使用。