| name | chrome-cdp |
| description | Interact with local Chrome browser session (only on explicit user approval after being asked to inspect, debug, or interact with a page open in Chrome) |
Chrome CDP
Lightweight Chrome DevTools Protocol CLI. Connects directly via WebSocket — no Puppeteer, works with 100+ tabs, instant connection.
Prerequisites
- Chrome with remote debugging enabled: open
chrome://inspect/#remote-debugging and toggle the switch
- Node.js 22+ (uses built-in WebSocket)
Commands
All commands use scripts/cdp.mjs. The <target> is a unique targetId prefix from list; copy the full prefix shown in the list output (for example 6BE827FA). The CLI rejects ambiguous prefixes.
Page discovery
scripts/cdp.mjs list
scripts/cdp.mjs info <target>
Run info first to orient yourself on any page.
Reading
scripts/cdp.mjs snap <target> [selector]
scripts/cdp.mjs text <target> [selector]
scripts/cdp.mjs html <target> [selector]
scripts/cdp.mjs eval <target> <expr>
scripts/cdp.mjs shot <target> [file]
scripts/cdp.mjs net <target>
scripts/cdp.mjs console <target> [count]
Watch out: avoid index-based selection (querySelectorAll(...)[i]) across multiple eval calls when the DOM can change between them. Collect all data in one eval or use stable selectors.
Navigation
scripts/cdp.mjs nav <target> <url>
scripts/cdp.mjs back <target>
scripts/cdp.mjs forward <target>
scripts/cdp.mjs reload <target>
scripts/cdp.mjs scroll <target> [direction]
Interaction
scripts/cdp.mjs click <target> <selector>
scripts/cdp.mjs clickxy <target> <x> <y>
scripts/cdp.mjs hover <target> <selector>
scripts/cdp.mjs focus <target> <selector>
scripts/cdp.mjs clear <target> <selector>
scripts/cdp.mjs type <target> <text>
scripts/cdp.mjs key <target> <key>
scripts/cdp.mjs select <target> <selector> <value>
Waiting
scripts/cdp.mjs wait <target> <selector> [ms]
scripts/cdp.mjs waitgone <target> <selector> [ms]
scripts/cdp.mjs loadall <target> <selector> [ms]
Advanced
scripts/cdp.mjs evalraw <target> <method> [json]
scripts/cdp.mjs stop [target]
Coordinates
shot saves an image at native resolution: image pixels = CSS pixels × DPR. CDP Input events (clickxy etc.) take CSS pixels.
CSS px = screenshot image px / DPR
shot prints the DPR for the current page. Typical Retina (DPR=2): divide screenshot coords by 2.
Tips
- Run
info after every action to confirm state changes.
- Prefer
snap over html for page structure. Use snap <target> <selector> to scope to a subtree and save tokens on large pages.
- Use
text instead of html when you only need the content — much cheaper in tokens.
- Form filling pattern:
focus → clear → type → key Tab (or key Enter to submit). The clear command uses native property setters so it works with React/framework-controlled inputs.
select matches by value first, then by visible text. On failure it lists all available options so you can self-correct.
- Use
hover for dropdown menus and tooltip reveals.
- Use
waitgone after actions that trigger loading spinners or toast notifications.
- Use
console to check for JS errors when something isn't working.
- Use
type (not eval) to enter text in cross-origin iframes — focus first, then type.
- Chrome shows an "Allow debugging" modal once per tab on first access. A background daemon keeps the session alive so subsequent commands need no further approval. Daemons auto-exit after 20 minutes of inactivity.