[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EXFF3XBZTPDBCA974V7051":3,"skill-same:01M7EXFF3XBZTPDBCA974V7051":132},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7EXFF3XBZTPDBCA974V7051","cdp",null,"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.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: cdp\ndescription: 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.\n---\n\n# CDP — `browser-harness-js` skill\n\nCustom 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.\n\nThe SDK lives in the skill's `sdk\u002F` directory. In the rest of this doc, `\u003Cskill-dir>` refers to wherever `npx skills add` installed the skill (Claude Code: `~\u002F.claude\u002Fskills\u002Fcdp`; Cursor: `~\u002F.cursor\u002Fskills\u002Fcdp`; other agents vary). The CLI should be on PATH as `browser-harness-js`.\n\n## Setup (once, first use)\n\n`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:\n\n```bash\n# macOS (Apple Silicon + Homebrew)\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js \u002Fopt\u002Fhomebrew\u002Fbin\u002Fbrowser-harness-js\n\n# macOS (Intel) \u002F most Linux — may need sudo\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js \u002Fusr\u002Flocal\u002Fbin\u002Fbrowser-harness-js\n\n# Linux without sudo (ensure ~\u002F.local\u002Fbin is on PATH)\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || { mkdir -p ~\u002F.local\u002Fbin && ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js ~\u002F.local\u002Fbin\u002Fbrowser-harness-js; }\n```\n\nThe 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.\n\n## How to use\n\nJust run `browser-harness-js '\u003CJS>'`. 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.\n\n```bash\nbrowser-harness-js 'await session.connect()'\nbrowser-harness-js 'await session.Page.navigate({url:\"https:\u002F\u002Fexample.com\"})'\nbrowser-harness-js '(await session.Runtime.evaluate({expression:\"document.title\",returnByValue:true})).result.value'\n```\n\nOutput is the **raw result content** — no `{ok,result}` envelope.\n\n| Result type | stdout |\n|---|---|\n| string                       | bare text, no JSON quotes (e.g. `Example Domain`) |\n| number \u002F boolean             | `42`, `true` |\n| object \u002F array (non-empty)   | compact JSON (e.g. `{\"frameId\":\"...\"}`, `[1,2,3]`) |\n| `undefined` \u002F `null` \u002F `\"\"` \u002F `{}` \u002F `[]` | empty (no output) |\n\n**Errors** go to **stderr**, exit code `1`. The CDP error message and JS stack are printed verbatim, e.g.:\n```\nError: CDP -32602: invalid params\n    at _call (...\u002Fsession.ts:117:33)\n    ...\n```\nDetect failure with `if browser-harness-js '...'; then ...; else handle_error; fi` or by checking `$?`.\n\n**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.\n\n```bash\nbrowser-harness-js \u003C\u003C'EOF'\nconst tabs = await listPageTargets();\nglobalThis.tid = tabs[0].targetId;\nawait session.use(globalThis.tid);\nreturn globalThis.tid;\nEOF\n```\n\n## CLI commands\n\n| Command | Behavior |\n|---|---|\n| `browser-harness-js '\u003Cjs>'`     | Auto-start server if needed, eval the JS, print result. |\n| `browser-harness-js \u003C\u003CEOF…EOF`  | Same, code from stdin. |\n| `browser-harness-js --status`   | Print health JSON (uptime, connected, sessionId) or exit 1 if down. |\n| `browser-harness-js --start`    | Explicit start (no-op if already running). |\n| `browser-harness-js --stop`     | Graceful shutdown. Drops session state. |\n| `browser-harness-js --restart`  | Stop + start fresh. |\n| `browser-harness-js --logs`     | `tail -f` the server log (`\u002Ftmp\u002Fbrowser-harness-js.log`). |\n\nEnv vars: `CDP_REPL_PORT` (default `9876`), `CDP_REPL_LOG` (default `\u002Ftmp\u002Fbrowser-harness-js.log`).\n\n## API surface inside snippets\n\nThese globals are pre-loaded — no imports needed:\n\n- `session` — the persistent `Session`. Has every CDP domain mounted: `session.Page`, `session.DOM`, `session.Runtime`, `session.Network`, … 56 domains, 652 methods total.\n- `listPageTargets()` — list real page targets via CDP's `Target.getTargets` (works on Chrome 144+ too), with `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs filtered out. No args — uses the connected session.\n- `detectBrowsers()` — scan OS-specific profile dirs for running Chromium-based browsers with remote debugging on. Returns `[{name, profileDir, port, wsPath, wsUrl, mtimeMs}]`, sorted by most recently launched.\n- `resolveWsUrl(opts)` — resolve a WS URL from `{wsUrl}` | `{port, host?}` | `{profileDir}`. For the no-args auto-detect flow, call `session.connect()` directly instead.\n- `CDP` — the generated namespaces (`CDP.Page`, `CDP.Runtime`, …) for type-name reference.\n\n### Calling a CDP method\n\nEvery method takes a single object argument matching the CDP wire params; it resolves to the typed return value (no `result` envelope, no `id` correlation — handled for you).\n\n```js\n\u002F\u002F no params\nawait session.DOM.enable()\n\n\u002F\u002F required params\nawait session.Page.navigate({ url: 'https:\u002F\u002Fexample.com' })\n\n\u002F\u002F all-optional params (object also optional)\nawait session.Page.captureScreenshot()\nawait session.Page.captureScreenshot({ format: 'png', quality: 80 })\n\n\u002F\u002F returns are stripped to the typed shape\nconst { root } = await session.DOM.getDocument()\nconst { nodeId } = await session.DOM.querySelector({ nodeId: root.nodeId, selector: 'h1' })\n```\n\n### Connecting\n\n**Default: just call `session.connect()` with no args.** It auto-detects running Chromium-based browsers (Chrome, Chromium, Edge, Brave, Arc, Vivaldi, Opera, Comet, Canary) by scanning OS-specific profile dirs for a `DevToolsActivePort` file, ordered by most-recently-launched, and picks the first one whose WebSocket accepts. OS-agnostic — works on macOS, Linux, Windows.\n\n```js\nawait session.connect()   \u002F\u002F auto-detect\n```\n\nUse `detectBrowsers()` first if you want to see what's available (or let the user pick) before connecting:\n\n```js\nconst found = await detectBrowsers()\n\u002F\u002F [{ name: 'Google Chrome', profileDir, port, wsPath, wsUrl, mtimeMs }, ...]\n```\n\n**Explicit forms** — use these only when auto-detect picks the wrong browser, or when you already know where to connect:\n\n| Form | When to use |\n|---|---|\n| `{ profileDir }` | Target a specific browser when several are running. Reads `\u003CprofileDir>\u002FDevToolsActivePort` directly. |\n| `{ wsUrl }` | You already have `ws:\u002F\u002F…\u002Fdevtools\u002Fbrowser\u002F\u003Cuuid>` (e.g. piped from elsewhere). |\n\n```js\nawait session.connect({ profileDir: '\u002FUsers\u002F\u003Cyou>\u002FLibrary\u002FApplication Support\u002FGoogle\u002FChrome' })\nawait session.connect({ wsUrl: 'ws:\u002F\u002F127.0.0.1:9222\u002Fdevtools\u002Fbrowser\u002F\u003Cuuid>' })\n```\n\nProfile paths by OS — use these with `{ profileDir }`:\n- macOS: `~\u002FLibrary\u002FApplication Support\u002F\u003CBrowser>` (e.g. `Google\u002FChrome`, `Comet`, `BraveSoftware\u002FBrave-Browser`, `Arc\u002FUser Data`)\n- Linux: `~\u002F.config\u002F\u003Cbrowser>` (e.g. `google-chrome`, `chromium`, `BraveSoftware\u002FBrave-Browser`)\n- Windows: `%LOCALAPPDATA%\\\u003CBrowser>\\User Data` (e.g. `Google\\Chrome`, `Microsoft\\Edge`, `BraveSoftware\\Brave-Browser`)\n\nPer-candidate WS-open timeout defaults to **5s** — live browsers answer with open\u002Fclose 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`:\n\n```js\nawait session.connect({ profileDir: '\u002FUsers\u002F\u003Cyou>\u002FLibrary\u002FApplication Support\u002FGoogle\u002FChrome', timeoutMs: 30_000 })\n```\n\n**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`).\n\n### Picking a target (tab)\n\nAfter `connect()`, call `session.use(targetId)` once; subsequent page-level calls (Page\u002FDOM\u002FRuntime\u002FNetwork\u002Fetc.) auto-route to that target's sessionId. `Browser.*` and `Target.*` calls always hit the browser endpoint.\n\n```js\nconst tabs = await listPageTargets()                     \u002F\u002F no args; uses the connected session\nconst sid  = await session.use(tabs[0].targetId)\nawait session.Page.enable()\nawait session.Page.navigate({ url: 'https:\u002F\u002Fexample.com' })\n```\n\n`listPageTargets()` uses CDP's `Target.getTargets` (not `\u002Fjson`), so it works on Chrome 144+ too. It already filters out `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs. Equivalent raw call:\n\n```js\nconst { targetInfos } = await session.Target.getTargets({})\nconst tabs = targetInfos.filter(t => t.type === 'page' && !t.url.startsWith('chrome:\u002F\u002F') && !t.url.startsWith('devtools:\u002F\u002F'))\n```\n\nTo switch tabs: `session.use(otherTargetId)`. To detach: `session.setActiveSession(undefined)`.\n\n### Events\n\n```js\n\u002F\u002F Subscribe (returns an unsubscribe fn)\nconst off = session.onEvent((method, params, sessionId) => { ... })\n\n\u002F\u002F Or wait for a single matching event with optional predicate + timeout\nawait session.Network.enable()\nconst ev = await session.waitFor(\n  'Page.frameNavigated',\n  (p) => p.frame.url.includes('example.com'),\n  10_000\n)\n```\n\n### Persisting state across calls\n\nEach snippet runs inside its own async wrapper, so its `let`\u002F`const` declarations vanish when it returns. To carry data forward, attach to `globalThis`:\n\n```bash\nbrowser-harness-js '(await listPageTargets()).forEach((t,i)=>globalThis[\"tab\"+i]=t.targetId)'\nbrowser-harness-js 'await session.use(globalThis.tab0)'\nbrowser-harness-js 'await session.Page.navigate({url:\"https:\u002F\u002Fexample.com\"})'\n```\n\n`session` itself, the active sessionId, and event subscribers are already preserved by the server — globals are only needed for ad-hoc data.\n\n## Connecting to a running Chrome (chrome:\u002F\u002Finspect flow)\n\nWhen attaching to the user's already-running browser:\n\n1. **Try `await session.connect()` first** (no args) — auto-detect handles every Chromium-based browser via `DevToolsActivePort`. If it returns, you're done.\n2. **If auto-detect fails** with `No running browser with remote debugging detected`, the user needs to turn it on. Open the inspect page:\n   ```bash\n   # macOS — prefer AppleScript over `open -a` (reuses current profile, avoids the profile picker)\n   osascript -e 'open location \"chrome:\u002F\u002Finspect\u002F#remote-debugging\"'\n\n   # Linux\n   google-chrome 'chrome:\u002F\u002Finspect\u002F#remote-debugging'     # or: chromium, google-chrome-stable\n\n   # Windows (PowerShell)\n   Start-Process chrome 'chrome:\u002F\u002Finspect\u002F#remote-debugging'\n   ```\n   Only macOS's AppleScript path avoids the profile picker; Linux\u002FWindows may prompt the user to pick a profile first.\n3. **Tick \"Discover network targets\"** in chrome:\u002F\u002Finspect, then click **Allow** when Chrome prompts.\n4. **If auto-detect picks the wrong browser** (multiple running, you want a specific one): list them with `await detectBrowsers()`, then `await session.connect({ profileDir: \u003Cthe one you want> })`.\n5. **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.\n\n## Working with targets (tabs)\n\n- **Filter Chrome internals.** `listPageTargets()` already drops `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs. If you call `Target.getTargets()` directly, filter manually.\n- **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.\n\n## Looking up a method\n\nThe full typed surface is in `\u003Cskill-dir>\u002Fsdk\u002Fgenerated.ts` (~655 KB, only loaded if you read it). Each method has its CDP description as a JSDoc comment plus typed `*Params` \u002F `*Return` interfaces in per-domain namespaces.\n\n```bash\ngrep -n \"navigate\" \u003Cskill-dir>\u002Fsdk\u002Fgenerated.ts | head\n```\n\n## Regenerating the SDK\n\nWhen the upstream protocol JSONs change, replace `sdk\u002Fbrowser_protocol.json` and\u002For `sdk\u002Fjs_protocol.json` and re-run:\n\n```bash\ncd \u003Cskill-dir>\u002Fsdk && bun gen.ts\nbrowser-harness-js --restart   # pick up the new bindings\n```\n\n## Files\n\nAll paths are relative to `\u003Cskill-dir>` (the install path — see top of this doc).\n\n- `\u002Fusr\u002Flocal\u002Fbin\u002Fbrowser-harness-js` → `\u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js` (the CLI)\n- `sdk\u002Frepl.ts` — HTTP server (`Bun.serve` on `127.0.0.1:9876`)\n- `sdk\u002Fsession.ts` — `Session` class (transport, connect, target routing, events)\n- `sdk\u002Fgenerated.ts` — codegen output: every CDP method as a typed wrapper\n- `sdk\u002Fgen.ts` — codegen script\n- `sdk\u002F{browser,js}_protocol.json` — upstream protocol (vendored)\n","# CDP — `browser-harness-js` skill\n\nCustom 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.\n\nThe SDK lives in the skill's `sdk\u002F` directory. In the rest of this doc, `\u003Cskill-dir>` refers to wherever `npx skills add` installed the skill (Claude Code: `~\u002F.claude\u002Fskills\u002Fcdp`; Cursor: `~\u002F.cursor\u002Fskills\u002Fcdp`; other agents vary). The CLI should be on PATH as `browser-harness-js`.\n\n## Setup (once, first use)\n\n`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:\n\n```bash\n# macOS (Apple Silicon + Homebrew)\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js \u002Fopt\u002Fhomebrew\u002Fbin\u002Fbrowser-harness-js\n\n# macOS (Intel) \u002F most Linux — may need sudo\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js \u002Fusr\u002Flocal\u002Fbin\u002Fbrowser-harness-js\n\n# Linux without sudo (ensure ~\u002F.local\u002Fbin is on PATH)\ncommand -v browser-harness-js >\u002Fdev\u002Fnull || { mkdir -p ~\u002F.local\u002Fbin && ln -sf \u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js ~\u002F.local\u002Fbin\u002Fbrowser-harness-js; }\n```\n\nThe 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.\n\n## How to use\n\nJust run `browser-harness-js '\u003CJS>'`. 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.\n\n```bash\nbrowser-harness-js 'await session.connect()'\nbrowser-harness-js 'await session.Page.navigate({url:\"https:\u002F\u002Fexample.com\"})'\nbrowser-harness-js '(await session.Runtime.evaluate({expression:\"document.title\",returnByValue:true})).result.value'\n```\n\nOutput is the **raw result content** — no `{ok,result}` envelope.\n\n| Result type | stdout |\n|---|---|\n| string                       | bare text, no JSON quotes (e.g. `Example Domain`) |\n| number \u002F boolean             | `42`, `true` |\n| object \u002F array (non-empty)   | compact JSON (e.g. `{\"frameId\":\"...\"}`, `[1,2,3]`) |\n| `undefined` \u002F `null` \u002F `\"\"` \u002F `{}` \u002F `[]` | empty (no output) |\n\n**Errors** go to **stderr**, exit code `1`. The CDP error message and JS stack are printed verbatim, e.g.:\n```\nError: CDP -32602: invalid params\n    at _call (...\u002Fsession.ts:117:33)\n    ...\n```\nDetect failure with `if browser-harness-js '...'; then ...; else handle_error; fi` or by checking `$?`.\n\n**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.\n\n```bash\nbrowser-harness-js \u003C\u003C'EOF'\nconst tabs = await listPageTargets();\nglobalThis.tid = tabs[0].targetId;\nawait session.use(globalThis.tid);\nreturn globalThis.tid;\nEOF\n```\n\n## CLI commands\n\n| Command | Behavior |\n|---|---|\n| `browser-harness-js '\u003Cjs>'`     | Auto-start server if needed, eval the JS, print result. |\n| `browser-harness-js \u003C\u003CEOF…EOF`  | Same, code from stdin. |\n| `browser-harness-js --status`   | Print health JSON (uptime, connected, sessionId) or exit 1 if down. |\n| `browser-harness-js --start`    | Explicit start (no-op if already running). |\n| `browser-harness-js --stop`     | Graceful shutdown. Drops session state. |\n| `browser-harness-js --restart`  | Stop + start fresh. |\n| `browser-harness-js --logs`     | `tail -f` the server log (`\u002Ftmp\u002Fbrowser-harness-js.log`). |\n\nEnv vars: `CDP_REPL_PORT` (default `9876`), `CDP_REPL_LOG` (default `\u002Ftmp\u002Fbrowser-harness-js.log`).\n\n## API surface inside snippets\n\nThese globals are pre-loaded — no imports needed:\n\n- `session` — the persistent `Session`. Has every CDP domain mounted: `session.Page`, `session.DOM`, `session.Runtime`, `session.Network`, … 56 domains, 652 methods total.\n- `listPageTargets()` — list real page targets via CDP's `Target.getTargets` (works on Chrome 144+ too), with `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs filtered out. No args — uses the connected session.\n- `detectBrowsers()` — scan OS-specific profile dirs for running Chromium-based browsers with remote debugging on. Returns `[{name, profileDir, port, wsPath, wsUrl, mtimeMs}]`, sorted by most recently launched.\n- `resolveWsUrl(opts)` — resolve a WS URL from `{wsUrl}` | `{port, host?}` | `{profileDir}`. For the no-args auto-detect flow, call `session.connect()` directly instead.\n- `CDP` — the generated namespaces (`CDP.Page`, `CDP.Runtime`, …) for type-name reference.\n\n### Calling a CDP method\n\nEvery method takes a single object argument matching the CDP wire params; it resolves to the typed return value (no `result` envelope, no `id` correlation — handled for you).\n\n```js\n\u002F\u002F no params\nawait session.DOM.enable()\n\n\u002F\u002F required params\nawait session.Page.navigate({ url: 'https:\u002F\u002Fexample.com' })\n\n\u002F\u002F all-optional params (object also optional)\nawait session.Page.captureScreenshot()\nawait session.Page.captureScreenshot({ format: 'png', quality: 80 })\n\n\u002F\u002F returns are stripped to the typed shape\nconst { root } = await session.DOM.getDocument()\nconst { nodeId } = await session.DOM.querySelector({ nodeId: root.nodeId, selector: 'h1' })\n```\n\n### Connecting\n\n**Default: just call `session.connect()` with no args.** It auto-detects running Chromium-based browsers (Chrome, Chromium, Edge, Brave, Arc, Vivaldi, Opera, Comet, Canary) by scanning OS-specific profile dirs for a `DevToolsActivePort` file, ordered by most-recently-launched, and picks the first one whose WebSocket accepts. OS-agnostic — works on macOS, Linux, Windows.\n\n```js\nawait session.connect()   \u002F\u002F auto-detect\n```\n\nUse `detectBrowsers()` first if you want to see what's available (or let the user pick) before connecting:\n\n```js\nconst found = await detectBrowsers()\n\u002F\u002F [{ name: 'Google Chrome', profileDir, port, wsPath, wsUrl, mtimeMs }, ...]\n```\n\n**Explicit forms** — use these only when auto-detect picks the wrong browser, or when you already know where to connect:\n\n| Form | When to use |\n|---|---|\n| `{ profileDir }` | Target a specific browser when several are running. Reads `\u003CprofileDir>\u002FDevToolsActivePort` directly. |\n| `{ wsUrl }` | You already have `ws:\u002F\u002F…\u002Fdevtools\u002Fbrowser\u002F\u003Cuuid>` (e.g. piped from elsewhere). |\n\n```js\nawait session.connect({ profileDir: '\u002FUsers\u002F\u003Cyou>\u002FLibrary\u002FApplication Support\u002FGoogle\u002FChrome' })\nawait session.connect({ wsUrl: 'ws:\u002F\u002F127.0.0.1:9222\u002Fdevtools\u002Fbrowser\u002F\u003Cuuid>' })\n```\n\nProfile paths by OS — use these with `{ profileDir }`:\n- macOS: `~\u002FLibrary\u002FApplication Support\u002F\u003CBrowser>` (e.g. `Google\u002FChrome`, `Comet`, `BraveSoftware\u002FBrave-Browser`, `Arc\u002FUser Data`)\n- Linux: `~\u002F.config\u002F\u003Cbrowser>` (e.g. `google-chrome`, `chromium`, `BraveSoftware\u002FBrave-Browser`)\n- Windows: `%LOCALAPPDATA%\\\u003CBrowser>\\User Data` (e.g. `Google\\Chrome`, `Microsoft\\Edge`, `BraveSoftware\\Brave-Browser`)\n\nPer-candidate WS-open timeout defaults to **5s** — live browsers answer with open\u002Fclose 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`:\n\n```js\nawait session.connect({ profileDir: '\u002FUsers\u002F\u003Cyou>\u002FLibrary\u002FApplication Support\u002FGoogle\u002FChrome', timeoutMs: 30_000 })\n```\n\n**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`).\n\n### Picking a target (tab)\n\nAfter `connect()`, call `session.use(targetId)` once; subsequent page-level calls (Page\u002FDOM\u002FRuntime\u002FNetwork\u002Fetc.) auto-route to that target's sessionId. `Browser.*` and `Target.*` calls always hit the browser endpoint.\n\n```js\nconst tabs = await listPageTargets()                     \u002F\u002F no args; uses the connected session\nconst sid  = await session.use(tabs[0].targetId)\nawait session.Page.enable()\nawait session.Page.navigate({ url: 'https:\u002F\u002Fexample.com' })\n```\n\n`listPageTargets()` uses CDP's `Target.getTargets` (not `\u002Fjson`), so it works on Chrome 144+ too. It already filters out `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs. Equivalent raw call:\n\n```js\nconst { targetInfos } = await session.Target.getTargets({})\nconst tabs = targetInfos.filter(t => t.type === 'page' && !t.url.startsWith('chrome:\u002F\u002F') && !t.url.startsWith('devtools:\u002F\u002F'))\n```\n\nTo switch tabs: `session.use(otherTargetId)`. To detach: `session.setActiveSession(undefined)`.\n\n### Events\n\n```js\n\u002F\u002F Subscribe (returns an unsubscribe fn)\nconst off = session.onEvent((method, params, sessionId) => { ... })\n\n\u002F\u002F Or wait for a single matching event with optional predicate + timeout\nawait session.Network.enable()\nconst ev = await session.waitFor(\n  'Page.frameNavigated',\n  (p) => p.frame.url.includes('example.com'),\n  10_000\n)\n```\n\n### Persisting state across calls\n\nEach snippet runs inside its own async wrapper, so its `let`\u002F`const` declarations vanish when it returns. To carry data forward, attach to `globalThis`:\n\n```bash\nbrowser-harness-js '(await listPageTargets()).forEach((t,i)=>globalThis[\"tab\"+i]=t.targetId)'\nbrowser-harness-js 'await session.use(globalThis.tab0)'\nbrowser-harness-js 'await session.Page.navigate({url:\"https:\u002F\u002Fexample.com\"})'\n```\n\n`session` itself, the active sessionId, and event subscribers are already preserved by the server — globals are only needed for ad-hoc data.\n\n## Connecting to a running Chrome (chrome:\u002F\u002Finspect flow)\n\nWhen attaching to the user's already-running browser:\n\n1. **Try `await session.connect()` first** (no args) — auto-detect handles every Chromium-based browser via `DevToolsActivePort`. If it returns, you're done.\n2. **If auto-detect fails** with `No running browser with remote debugging detected`, the user needs to turn it on. Open the inspect page:\n   ```bash\n   # macOS — prefer AppleScript over `open -a` (reuses current profile, avoids the profile picker)\n   osascript -e 'open location \"chrome:\u002F\u002Finspect\u002F#remote-debugging\"'\n\n   # Linux\n   google-chrome 'chrome:\u002F\u002Finspect\u002F#remote-debugging'     # or: chromium, google-chrome-stable\n\n   # Windows (PowerShell)\n   Start-Process chrome 'chrome:\u002F\u002Finspect\u002F#remote-debugging'\n   ```\n   Only macOS's AppleScript path avoids the profile picker; Linux\u002FWindows may prompt the user to pick a profile first.\n3. **Tick \"Discover network targets\"** in chrome:\u002F\u002Finspect, then click **Allow** when Chrome prompts.\n4. **If auto-detect picks the wrong browser** (multiple running, you want a specific one): list them with `await detectBrowsers()`, then `await session.connect({ profileDir: \u003Cthe one you want> })`.\n5. **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.\n\n## Working with targets (tabs)\n\n- **Filter Chrome internals.** `listPageTargets()` already drops `chrome:\u002F\u002F` and `devtools:\u002F\u002F` URLs. If you call `Target.getTargets()` directly, filter manually.\n- **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.\n\n## Looking up a method\n\nThe full typed surface is in `\u003Cskill-dir>\u002Fsdk\u002Fgenerated.ts` (~655 KB, only loaded if you read it). Each method has its CDP description as a JSDoc comment plus typed `*Params` \u002F `*Return` interfaces in per-domain namespaces.\n\n```bash\ngrep -n \"navigate\" \u003Cskill-dir>\u002Fsdk\u002Fgenerated.ts | head\n```\n\n## Regenerating the SDK\n\nWhen the upstream protocol JSONs change, replace `sdk\u002Fbrowser_protocol.json` and\u002For `sdk\u002Fjs_protocol.json` and re-run:\n\n```bash\ncd \u003Cskill-dir>\u002Fsdk && bun gen.ts\nbrowser-harness-js --restart   # pick up the new bindings\n```\n\n## Files\n\nAll paths are relative to `\u003Cskill-dir>` (the install path — see top of this doc).\n\n- `\u002Fusr\u002Flocal\u002Fbin\u002Fbrowser-harness-js` → `\u003Cskill-dir>\u002Fsdk\u002Fbrowser-harness-js` (the CLI)\n- `sdk\u002Frepl.ts` — HTTP server (`Bun.serve` on `127.0.0.1:9876`)\n- `sdk\u002Fsession.ts` — `Session` class (transport, connect, target routing, events)\n- `sdk\u002Fgenerated.ts` — codegen output: every CDP method as a typed wrapper\n- `sdk\u002Fgen.ts` — codegen script\n- `sdk\u002F{browser,js}_protocol.json` — upstream protocol (vendored)\n",{"name":5,"description":7},"main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","05-技能与代理开发\u002Fbrowser-harness-js",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill cdp",{"tool":38,"command":39},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill cdp",{"tool":41,"command":42},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill cdp","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002FSKILL.md",true,[46,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"interaction-skills\u002Fconnection.md","REFERENCE","参考文档",4062,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fconnection.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"interaction-skills\u002Fcookies.md",2117,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fcookies.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"interaction-skills\u002Fcross-origin-iframes.md",3153,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fcross-origin-iframes.md",{"path":61,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":62,"sourceHtmlUrl":63},"interaction-skills\u002Fdialogs.md",2540,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fdialogs.md",{"path":65,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":66,"sourceHtmlUrl":67},"interaction-skills\u002Fdownloads.md",3123,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fdownloads.md",{"path":69,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":70,"sourceHtmlUrl":71},"interaction-skills\u002Fdrag-and-drop.md",3387,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fdrag-and-drop.md",{"path":73,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":74,"sourceHtmlUrl":75},"interaction-skills\u002Fdropdowns.md",3543,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fdropdowns.md",{"path":77,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":78,"sourceHtmlUrl":79},"interaction-skills\u002Fiframes.md",2655,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fiframes.md",{"path":81,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":82,"sourceHtmlUrl":83},"interaction-skills\u002Fnetwork-requests.md",3933,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fnetwork-requests.md",{"path":85,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":86,"sourceHtmlUrl":87},"interaction-skills\u002Fprint-as-pdf.md",3004,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fprint-as-pdf.md",{"path":89,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":90,"sourceHtmlUrl":91},"interaction-skills\u002Fscreenshots.md",2340,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fscreenshots.md",{"path":93,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":94,"sourceHtmlUrl":95},"interaction-skills\u002Fscrolling.md",3156,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fscrolling.md",{"path":97,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":98,"sourceHtmlUrl":99},"interaction-skills\u002Fshadow-dom.md",3015,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fshadow-dom.md",{"path":101,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":102,"sourceHtmlUrl":103},"interaction-skills\u002Ftabs.md",2652,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Ftabs.md",{"path":105,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":106,"sourceHtmlUrl":107},"interaction-skills\u002Fuploads.md",2580,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fuploads.md",{"path":109,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":110,"sourceHtmlUrl":111},"interaction-skills\u002Fviewport.md",2938,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Finteraction-skills\u002Fviewport.md",{"path":113,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":114,"sourceHtmlUrl":115},"README.md",4228,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002FREADME.md",{"path":117,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":118,"sourceHtmlUrl":119},"sdk\u002Fbrowser_protocol.json",1406521,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Fsdk\u002Fbrowser_protocol.json",{"path":121,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":122,"sourceHtmlUrl":123},"sdk\u002Fjs_protocol.json",181640,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Fsdk\u002Fjs_protocol.json",{"path":125,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":126,"sourceHtmlUrl":127},"sdk\u002Fpackage.json",239,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Fsdk\u002Fpackage.json",{"path":129,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":130,"sourceHtmlUrl":131},"sdk\u002Ftsconfig.json",335,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fbrowser-harness-js\u002Fsdk\u002Ftsconfig.json",[133,141,146,153,160,167],{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":140},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":142,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":143,"categories":144,"keywords":145,"publishedAt":140},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":147,"name":148,"nameZh":6,"description":149,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":140},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":154,"name":155,"nameZh":6,"description":156,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":157,"categories":158,"keywords":159,"publishedAt":140},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":161,"name":162,"nameZh":6,"description":163,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":164,"categories":165,"keywords":166,"publishedAt":140},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":168,"name":169,"nameZh":6,"description":170,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":171,"categories":172,"keywords":173,"publishedAt":140},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]