跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 cdp

Cdp

从 JavaScript 通过 DevTools 协议驱动 Chrome 。 通过 " 浏览器-harness-js " CLI运行JS片段——它自动喷出一个长寿的包子HTTP服务器,上面有一个完整的CDP ' session " ,以及每个呼叫( " 浏览器-harness-js " 等待会议)。 page.navigate (.)'' 执行时与相同的持续连接. 会话,活动目标,以及全球人通过呼叫生存. 当用户想要通过 CDP 自动化,脚本,或检查 Chrome 浏览器时使用—— 单标签或多标签, 附加到现有的 Chrome 上, 或附加到用 -- remote-debugging-port 启动的新版本上.

657 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

从 JavaScript 通过 DevTools 协议驱动 Chrome 。 通过 " 浏览器-harness-js " CLI运行JS片段——它自动喷出一个长寿的包子HTTP服务器,上面有一个完整的CDP ' session " ,以及每个呼叫( " 浏览器-harness-js " 等待会议)。 page.navigate (.)'' 执行时与相同的持续连接. 会话、活动目标和全球在呼叫中生存

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:CDP — `browser-harness-js` skill、Setup (once, first use)、macOS (Apple Silicon + Homebrew)、macOS (Intel) / most Linux — may need sudo、Linux without sudo (ensure ~/.local/bin is on PATH)、How to use。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

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 against the same persistent connection. Session, active target, and globals survive across calls. Use when the user wants to automate, script, or inspect a Chrome browser via CDP — single tab or multi-tab, attach to existing Chrome or to a new one launched with --remote-debugging-port.

CDP — `browser-harness-js` skillSetup (once, first use)macOS (Apple Silicon + Homebrew)macOS (Intel) / most Linux — may need sudoLinux without sudo (ensure ~/.local/bin is on PATH)How to useCLI commandsAPI surface inside snippetsCalling a CDP methodConnectingPicking a target (tab)Events

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
cdp
description
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 against the same persistent connection. Session, active target, and globals survive across calls. Use when the user wants to automate, script, or inspect a Chrome browser via CDP — single tab or multi-tab, attach to existing Chrome or to a new one launched with --remote-debugging-port.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「cdp」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-b3293ff72b831390-%E6%95%B0%E6%8D%AEp.html
请存为 .cursor/skills/cdp/SKILL.md 或 .claude/skills/cdp/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/browser-use/browser-harness-js' --list

npx skills add 'https://github.com/browser-use/browser-harness-js' --skill 'cdp'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: cdp description: 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 against the same persistent connection. Session, active target, and globals survive across calls. Use when the user wants to automate, script, or inspect a Chrome browser via CDP — single tab or multi-tab, attach to existing Chrome or to a new one launched with --remote-debugging-port. --- # CDP — `browser-harness-js` skill Custom codegen'd CDP SDK (every method from browser_protocol.json + js_protocol.json gets a typed wrapper) plus a tiny HTTP server that holds one persistent CDP `Session`. The `browser-harness-js` CLI auto-starts the server on first use and forwards JS snippets to it. The SDK lives in the skill's `sdk/` directory. In the rest of this doc, `` refers to wherever `npx skills add` installed the skill (Claude Code: `~/.claude/skills/cdp`; Cursor: `~/.cursor/skills/cdp`; other agents vary). The CLI should be on PATH as `browser-harness-js`. ## Setup (once, first use) `npx skills add` drops the skill into your agent's skills directory but does NOT put the CLI on PATH. Before the first call, verify it's reachable and symlink it into any directory on your PATH if not: ```bash # macOS (Apple Silicon + Homebrew) command -v browser-harness-js >/dev/null || ln -sf /sdk/browser-harness-js /opt/homebrew/bin/browser-harness-js # macOS (Intel) / most Linux — may need sudo command -v browser-harness-js >/dev/null || ln -sf /sdk/browser-harness-js /usr/local/bin/browser-harness-js # Linux without sudo (ensure ~/.local/bin is on PATH) command -v browser-harness-js >/dev/null || { mkdir -p ~/.local/bin && ln -sf /sdk/browser-harness-js ~/.local/bin/browser-harness-js; } ``` The CLI auto-installs `bun` on first run if it's missing (the server is Bun-native). Set `BROWSER_HARNESS_SKIP_BUN_INSTALL=1` to opt out. ## How to use Just run `browser-harness-js ''`. The first call spawns the server in the background; subsequent calls hit the same process and so reuse the same `session`, the same WebSocket to Chrome, and any globals you set. ```bash browser-harness-js 'await session.connect()' browser-harness-js 'await session.Page.navigate({url:"https://example.com"})' browser-harness-js '(await session.Runtime.evaluate({expression:"document.title",returnByValue:true})).result.value' ``` Output is the **raw result content** — no `{ok,result}` envelope. | Result type | stdout | |---|---| | string | bare text, no JSON quotes (e.g. `Example Domain`) | | number / boolean | `42`, `true` | | object / array (non-empty) | compact JSON (e.g. `{"frameId":"..."}`, `[1,2,3]`) | | `undefined` / `null` / `""` / `{}` / `[]` | empty (no output) | **Errors** go to **stderr**, exit code `1`. The CDP error message and JS stack are printed verbatim, e.g.: ``` Error: CDP -32602: invalid params at _call (.../session.ts:117:33) ... ``` Detect failure with `if browser-harness-js '...'; then ...; else handle_error; fi` or by checking `$?`. **Multi-line snippets via stdin (heredoc).** Important: a multi-statement snippet does NOT auto-return the last expression — write `return X` explicitly. Single-expression snippets passed as the first argument DO auto-return. ```bash browser-harness-js <<'EOF' const tabs = await listPageTargets(); globalThis.tid = tabs[0].targetId; await session.use(globalThis.tid); return globalThis.tid; EOF ``` ## CLI commands | Command | Behavior | |---|---| | `browser-harness-js ''` | Auto-start server if needed, eval the JS, print result. | | `browser-harness-js </DevToolsActivePort` directly. | | `{ wsUrl }` | You already have `ws://…/devtools/browser/` (e.g. piped from elsewhere). | ```js await session.connect({ profileDir: '/Users//Library/Application Support/Google/Chrome' }) await session.connect({ wsUrl: 'ws://127.0.0.1:9222/devtools/browser/' }) ``` Profile paths by OS — use these with `{ profileDir }`: - macOS: `~/Library/Application Support/` (e.g. `Google/Chrome`, `Comet`, `BraveSoftware/Brave-Browser`, `Arc/User Data`) - Linux: `~/.config/` (e.g. `google-chrome`, `chromium`, `BraveSoftware/Brave-Browser`) - Windows: `%LOCALAPPDATA%\\User Data` (e.g. `Google\Chrome`, `Microsoft\Edge`, `BraveSoftware\Brave-Browser`) Per-candidate WS-open timeout defaults to **5s** — live browsers answer with open/close within ~100ms, so 5s is already generous. The only case where 5s is too short is when Chrome is showing the **Allow** popup and waiting on the user to click. If you expect that, pass `timeoutMs: 30000`: ```js await session.connect({ profileDir: '/Users//Library/Application Support/Google/Chrome', timeoutMs: 30_000 }) ``` **If you see `No detected browser accepted a connection`** — the browsers have `DevToolsActivePort` files but none are currently serving WS. Most common cause: remote-debugging is enabled but the user hasn't clicked **Allow** on the prompt yet. Tell them to click Allow, then retry (or bump `timeoutMs`). ### Picking a target (tab) After `connect()`, call `session.use(targetId)` once; subsequent page-level calls (Page/DOM/Runtime/Network/etc.) auto-route to that target's sessionId. `Browser.*` and `Target.*` calls always hit the browser endpoint. ```js const tabs = await listPageTargets() // no args; uses the connected session const sid = await session.use(tabs[0].targetId) await session.Page.enable() await session.Page.navigate({ url: 'https://example.com' }) ``` `listPageTargets()` uses CDP's `Target.getTargets` (not `/json`), so it works on Chrome 144+ too. It already filters out `chrome://` and `devtools://` URLs. Equivalent raw call: ```js const { targetInfos } = await session.Target.getTargets({}) const tabs = targetInfos.filter(t => t.type === 'page' && !t.url.startsWith('chrome://') && !t.url.startsWith('devtools://')) ``` To switch tabs: `session.use(otherTargetId)`. To detach: `session.setActiveSession(undefined)`. ### Events ```js // Subscribe (returns an unsubscribe fn) const off = session.onEvent((method, params, sessionId) => { ... }) // Or wait for a single matching event with optional predicate + timeout await session.Network.enable() const ev = await session.waitFor( 'Page.frameNavigated', (p) => p.frame.url.includes('example.com'), 10_000 ) ``` ### Persisting state across calls Each snippet runs inside its own async wrapper, so its `let`/`const` declarations vanish when it returns. To carry data forward, attach to `globalThis`: ```bash browser-harness-js '(await listPageTargets()).forEach((t,i)=>globalThis["tab"+i]=t.targetId)' browser-harness-js 'await session.use(globalThis.tab0)' browser-harness-js 'await session.Page.navigate({url:"https://example.com"})' ``` `session` itself, the active sessionId, and event subscribers are already preserved by the server — globals are only needed for ad-hoc data. ## Connecting to a running Chrome (chrome://inspect flow) When attaching to the user's already-running browser: 1. **Try `await session.connect()` first** (no args) — auto-detect handles every Chromium-based browser via `DevToolsActivePort`. If it returns, you're done. 2. **If auto-detect fails** with `No running browser with remote debugging detected`, the user needs to turn it on. Open the inspect page: ```bash # macOS — prefer AppleScript over `open -a` (reuses current profile, avoids the profile picker) osascript -e 'open location "chrome://inspect/#remote-debugging"' # Linux google-chrome 'chrome://inspect/#remote-debugging' # or: chromium, google-chrome-stable # Windows (PowerShell) Start-Process chrome 'chrome://inspect/#remote-debugging' ``` Only macOS's AppleScript path avoids the profile picker; Linux/Windows may prompt the user to pick a profile first. 3. **Tick "Discover network targets"** in chrome://inspect, then click **Allow** when Chrome prompts. 4. **If auto-detect picks the wrong browser** (multiple running, you want a specific one): list them with `await detectBrowsers()`, then `await session.connect({ profileDir: })`. 5. **If `session.connect()` returns `No detected browser accepted a connection`**, the user has remote-debugging on but hasn't clicked **Allow** yet. Tell them to click it and retry, or pass `timeoutMs: 30000` to wait for the click. ## Working with targets (tabs) - **Filter Chrome internals.** `listPageTargets()` already drops `chrome://` and `devtools://` URLs. If you call `Target.getTargets()` directly, filter manually. - **CDP target order ≠ visible tab-strip order.** When the user says "the first tab I can see", use a screenshot or page title to identify it — `Target.activateTarget` only switches to a known targetId. ## Looking up a method The full typed surface is in `/sdk/generated.ts` (~655 KB, only loaded if you read it). Each method has its CDP description as a JSDoc comment plus typed `*Params` / `*Return` interfaces in per-domain namespaces. ```bash grep -n "navigate" /sdk/generated.ts | head ``` ## Regenerating the SDK When the upstream protocol JSONs change, replace `sdk/browser_protocol.json` and/or `sdk/js_protocol.json` and re-run: ```bash cd /sdk && bun gen.ts browser-harness-js --restart # pick up the new bindings ``` ## Files All paths are relative to `` (the install path — see top of this doc). - `/usr/local/bin/browser-harness-js` → `/sdk/browser-harness-js` (the CLI) - `sdk/repl.ts` — HTTP server (`Bun.serve` on `127.0.0.1:9876`) - `sdk/session.ts` — `Session` class (transport, connect, target routing, events) - `sdk/generated.ts` — codegen output: every CDP method as a typed wrapper - `sdk/gen.ts` — codegen script - `sdk/{browser,js}_protocol.json` — upstream protocol (vendored)

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…