cdp

cdp is a Go module for Chrome DevTools Protocol automation. It includes a live browser CLI, a txtar script runner, and a Go test harness for repeatable browser workflows.
The browser-automation stack has three primary layers:
cmd/cdp: live CDP operation, MCP tools, browser attach, screenshots, HAR, raw CDP, and page artifacts.
cdpscript: executable txtar scripts that turn browser interactions into Unix-style tools.
cdpscripttest: rsc.io/script-style browser fixtures for Go tests, including a bridge that runs real cdpscript archives.
For MCP actions tied to an inspected page, see browser observations and actions.
Commands
chrome-to-har: focused HAR capture CLI
cdp: the main Chrome/CDP CLI
churl: browser-backed fetch and page extraction
chdb: Chrome-focused debugger workflow
ndp: Node/V8 debugger workflow
cdpscript: run CDP scripts
cdpscripttest: test CDP scripts
Install
The module requires Go 1.26 or newer.
Install the broad CDP CLI:
go install github.com/tmc/cdp/cmd/cdp@latest
Install individual tools:
go install github.com/tmc/cdp/cmd/chrome-to-har@latest
go install github.com/tmc/cdp/cmd/cdp@latest
go install github.com/tmc/cdp/cmd/churl@latest
go install github.com/tmc/cdp/cmd/chdb@latest
go install github.com/tmc/cdp/cmd/ndp@latest
go install github.com/tmc/cdp/cmd/cdpscript@latest
go install github.com/tmc/cdp/cmd/cdpscripttest@latest
Quick Start
Attach to a browser the user is already using:
cdp attach --port 9222
cdp --remote-host localhost --remote-port 9222 --tab <target-id> --shell
cdp --remote-host localhost --remote-port 9222 --tab <target-id> --await --format json --js 'document.title'
Run a repeatable browser script:
cdpscript script.txtar
cdpscript --tab <target-id> --port 9222 script.txtar
cdp run --tab <target-id> --port 9222 script.txtar
Test browser behavior from Go:
e := cdpscripttest.NewEngine()
cdpscripttest.Test(t, e, allocCtx, "http://localhost:8080", "testdata/*.txt", nil)
For cdpscript-format txtars, use cdpscripttest.RunCDPScript so tests run the same runtime used by cdpscript and cdp run.
err := cdpscripttest.RunCDPScript(ctx, "testdata/login.txtar", cdpscripttest.CDPScriptRunOptions{
Headless: true,
Env: []string{"BASE_URL=http://localhost:8080"},
})
Capture network activity with chrome-to-har:
go install github.com/tmc/cdp/cmd/chrome-to-har@latest
chrome-to-har --url https://example.com --output out.har
Capture network activity with cdp:
cdp --headless --url https://example.com --har out.har --timeout 10
Use --shell when you want to browse interactively while recording:
cdp --url https://example.com --har out.har --shell
Evaluate JavaScript in a page:
cdp --headless --url https://example.com --js 'document.title'
Fetch a page with browser execution:
churl https://example.com
Attach to a Node inspector target:
ndp node attach 9229
Common Tasks
Capture authenticated browser traffic with an existing profile:
chrome-to-har --profile "Default" \
--url https://app.example.com \
--wait-for '#app-root' \
--output app.har
Render a JavaScript-heavy page to text:
churl --output-format=text --wait-for ".loaded" https://example.com
Take a screenshot or extract content from a page:
cdp --url https://example.com --screenshot 'full page.png'
cdp --url https://example.com --extract 'h1'
cdp --url https://example.com --render body
Connect to an existing Chrome instance:
cdp attach --port 9222
cdp --remote-host localhost --remote-port 9222 --tab <tab-id> --js 'document.title'
Connect to a remote browser:
cdp --remote-host 10.0.0.5 --remote-port 9222 --list-tabs
churl --remote-host 10.0.0.5 --remote-port 9222 https://example.com
Use ndp against a Node inspector:
node --inspect=9229 app.js
ndp node attach 9229
Run and test CDP scripts:
cdpscript login.txtar
cdpscripttest --url http://localhost:8090 testdata/login.txt
What chrome-to-har Does
chrome-to-har is the focused capture entry point. It is useful when you want HAR output, streaming entry logs, profile-based browsing, or differential capture reports.
What cdp Does
The main cdp command is the broader general-purpose entry point. It goes beyond chrome-to-har and can: