| name | cli-cdp |
| description | Chrome DevTools CLI for browser automation via shell commands. Use when interacting with web pages from the command line — navigating, clicking, filling forms, inspecting console/network, taking screenshots, or extracting page content. Triggers on: browse a page, automate Chrome, inspect console, check network requests, take a screenshot, fill a form, click a button. |
Chrome DevTools CLI (cdp-cli)
CLI for Chrome DevTools Protocol. All list commands output NDJSON (one JSON
object per line) — grep/tail/jq friendly. Requires Chrome running with remote
debugging.
Prerequisites
Chrome must be running with --remote-debugging-port:
cdp-cli launch
Or start Chrome manually with --remote-debugging-port=9222 and pass
--cdp-url http://localhost:9222.
Page Identification
All commands taking <page> accept a page ID or a title substring.
Use cdp-cli tabs to discover pages.
cdp-cli tabs
cdp-cli tabs | grep "example"
Token-Conscious Defaults (Critical)
cdp-cli is designed to minimize token usage by default:
- console returns bare strings (not JSON objects) and only the last 10
messages. Add
--with-type, --with-timestamp, --with-source only when
needed. Use -v for all fields.
- snapshot defaults to accessibility tree (
--format ax) which is compact.
Use --format text for plain text, --format dom for full DOM (heavy).
- network collects for only 0.1s by default. Increase with
--duration.
Strategy: Start with defaults, add verbosity flags only when needed.
Commands
Page Management
cdp-cli tabs
cdp-cli new "https://example.com"
cdp-cli new
cdp-cli go "<page>" "https://url.com"
cdp-cli go "<page>" back
cdp-cli go "<page>" forward
cdp-cli go "<page>" reload
cdp-cli close "<page>"
Snapshot & Evaluation
cdp-cli snapshot "<page>"
cdp-cli snapshot "<page>" -f text
cdp-cli snapshot "<page>" -f dom
cdp-cli eval "<page>" "document.title"
cdp-cli eval "<page>" "Array.from(document.querySelectorAll('h1')).map(h => h.textContent)"
Use the accessibility tree to discover elements by role/name, then construct
CSS selectors for click/fill.
Console
cdp-cli console "<page>"
cdp-cli console "<page>" -n 50
cdp-cli console "<page>" --all
cdp-cli console "<page>" -t error
cdp-cli console "<page>" -d 2
cdp-cli console "<page>" -i
cdp-cli console "<page>" -v
cdp-cli console "<page>" --with-type
cdp-cli console "<page>" --with-source
When truncated, stderr shows: (N messages skipped. Use --tail M or --all to see more)
Network
cdp-cli network "<page>"
cdp-cli network "<page>" -d 5
cdp-cli network "<page>" -t fetch
cdp-cli network "<page>" -d 5 -t fetch
Filter results with grep:
cdp-cli network "<page>" | grep '"status":4'
cdp-cli network "<page>" | grep '"status":404'
Input Automation
cdp-cli click "<page>" "button"
cdp-cli click "<page>" "button" -d
cdp-cli click "<page>" "button" -g
cdp-cli click "<page>" --node 42
cdp-cli click "<page>" "button" -w 5000
cdp-cli fill "<page>" "user@example.com" "input[name='email']"
cdp-cli fill "<page>" "secret" "input[type='password']"
cdp-cli key "<page>" enter
cdp-cli key "<page>" tab
cdp-cli key "<page>" escape
Screenshots
cdp-cli screenshot "<page>" screenshot.jpg
cdp-cli screenshot "<page>" out.png -f png
cdp-cli screenshot "<page>" out.webp -f webp
cdp-cli screenshot "<page>" out.jpg -q 50
Error Handling
All errors output NDJSON with "error": true:
{ "error": true, "message": "Page not found: example", "code": "PAGE_NOT_FOUND" }
Common Workflows
Inspect and Interact
cdp-cli tabs | grep "example"
cdp-cli snapshot "example"
cdp-cli fill "example" "query" "input"
cdp-cli click "example" "button[type='submit']"
cdp-cli screenshot "example" result.jpg
Debug Console Errors
cdp-cli console "localhost" -t error -d 10
cdp-cli console "localhost" -t error -v
Monitor Network
cdp-cli network "localhost" -d 5 | grep '"status":4'
cdp-cli network "localhost" -d 5 -t fetch
Form Automation
cdp-cli new "http://localhost:3000/login"
cdp-cli fill "localhost" "user@example.com" "#email"
cdp-cli fill "localhost" "password123" "#password"
cdp-cli click "localhost" "button[type=submit]"
sleep 2
cdp-cli eval "localhost" "document.querySelector('.success')?.textContent"
Global Options
| Option | Default | Description |
|---|
--cdp-url | http://localhost:9223 | Chrome DevTools Protocol URL |
--help | — | Show help |
--version | — | Show version |