| name | agent-browser |
| description | Vercel agent-browser — Rust CLI for AI-driven browser automation via CDP. Use when: "agent-browser", "browse website", "automate browser", "scrape with browser", "fill form", "click button", "take screenshot", "browser automation", "headless chrome", "web interaction", "accessibility snapshot", "browser refs". Deterministic ref-based selectors, JSON output, daemon architecture. Replaces Playwright/Puppeteer for agent workflows.
|
agent-browser — AI Browser Automation CLI
Rust-native CLI by Vercel Labs. Persistent daemon per session, CDP-based, deterministic ref selectors (@e1, @e2), JSON output. Built for AI agents.
Repo: github.com/vercel-labs/agent-browser | License: Apache 2.0
Install
npm install -g agent-browser
agent-browser install
brew install agent-browser && agent-browser install
cargo install agent-browser && agent-browser install
agent-browser install --with-deps
Upgrade: agent-browser upgrade
Core Concept: Refs
Every snapshot assigns deterministic refs (@e1, @e2, ...) to DOM elements. Use refs instead of CSS selectors — they're stable within a snapshot, semantic, and LLM-friendly.
agent-browser open https://example.com
agent-browser snapshot -i
agent-browser click @e3
After any DOM change (navigation, AJAX, form submit) — re-snapshot to get fresh refs.
Essential Commands
Navigation
agent-browser open <url>
agent-browser back | forward | reload
Snapshot (primary way to "see" the page)
agent-browser snapshot
agent-browser snapshot -i
agent-browser snapshot -c
agent-browser snapshot -d 3
agent-browser snapshot -s "#main"
agent-browser snapshot --json
Interaction
agent-browser click <ref|selector>
agent-browser fill <ref> "text"
agent-browser type <ref> "text"
agent-browser select <ref> "option"
agent-browser check|uncheck <ref>
agent-browser hover <ref>
agent-browser press Enter|Tab|Escape
agent-browser press Control+a
agent-browser scroll down 500
agent-browser upload <ref> file.pdf
Data Extraction
agent-browser get text <ref>
agent-browser get html <ref>
agent-browser get value <ref>
agent-browser get attr <ref> href
agent-browser get title
agent-browser get url
Screenshot & PDF
agent-browser screenshot [path]
agent-browser screenshot --full
agent-browser screenshot --annotate
agent-browser pdf output.pdf
Wait
agent-browser wait <ref>
agent-browser wait 2000
agent-browser wait --load networkidle
agent-browser wait --url "**/dashboard"
agent-browser wait --text "Success"
agent-browser wait <ref> --state hidden
Semantic Locators (alternative to refs)
agent-browser find role button click --name "Submit"
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "test@test.com"
agent-browser find placeholder "Search" fill "query"
agent-browser find testid "login-btn" click
Session Management
agent-browser session list
agent-browser --session myapp <cmd>
agent-browser close
agent-browser close --all
Tabs
agent-browser tab
agent-browser tab new [url]
agent-browser tab 2
agent-browser tab close
AI Agent Workflow Pattern
Standard loop for any AI agent:
agent-browser open https://target.com
agent-browser snapshot -i --json
agent-browser fill @e2 "search query"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i --json
agent-browser get text @e5
Repeat 2-5 until task complete. Always close when done.
Batch Execution
When exact sequence is known upfront:
cat << 'EOF' | agent-browser batch --json
[
["open", "https://example.com/login"],
["fill", "@e1", "user@example.com"],
["fill", "@e2", "password123"],
["click", "@e3"],
["wait", "--load", "networkidle"],
["screenshot", "result.png"]
]
EOF
--bail stops on first error.
Authentication & State Persistence
echo "pass" | agent-browser auth save myapp \
--url https://app.example.com/login \
--username user@example.com --password-stdin
agent-browser auth login myapp
agent-browser --session-name myapp open https://app.example.com
agent-browser close
agent-browser --session-name myapp open https://app.example.com/dashboard
Manual state save/load:
agent-browser state save auth.json
agent-browser state load auth.json
Network Control
agent-browser network requests
agent-browser network requests --type xhr,fetch
agent-browser network route "**/analytics" --abort
agent-browser network route "**/api/*" --body '{"mock":true}'
agent-browser network har start && agent-browser network har stop output.har
Device Emulation
agent-browser set device "iPhone 14"
agent-browser set viewport 1920 1080
agent-browser set viewport 1920 1080 2
agent-browser set media dark
agent-browser set geo 52.2297 21.0122
Configuration
Priority: CLI flags > env vars > ./agent-browser.json > ~/.agent-browser/config.json
Key env vars:
AGENT_BROWSER_SESSION=myapp
AGENT_BROWSER_HEADED=1
AGENT_BROWSER_EXECUTABLE_PATH=/path
AGENT_BROWSER_PROXY=http://host:port
AGENT_BROWSER_DEFAULT_TIMEOUT=25000
AGENT_BROWSER_IDLE_TIMEOUT_MS=60000
AGENT_BROWSER_ENCRYPTION_KEY=<64hex>
AGENT_BROWSER_ALLOWED_DOMAINS=a.com,b.com
AGENT_BROWSER_MAX_OUTPUT=50000
Config file (agent-browser.json):
{
"headed": false,
"proxy": "http://localhost:8080",
"profile": "./browser-data",
"userAgent": "my-agent/1.0",
"screenshotDir": "./shots",
"colorScheme": "dark"
}
Key CLI flags: --json, --session <name>, --profile <name|path>, --headed, --proxy <url>, --ignore-https-errors, --annotate, --engine lightpanda, --provider <cloud>, --content-boundaries, --no-auto-dialog, --debug
Safety Features for AI
--content-boundaries
--max-output 50000
--allowed-domains a.com,b.com
--action-policy policy.json
--confirm-actions eval,download
Cloud Providers
For scalable/CI deployments: --provider <name>
Supported: AgentCore, Browserbase, Browserless, BrowserUse, Kernel
Gotchas
- Refs invalidate on DOM change — always re-snapshot after navigation/AJAX/form submit
- Daemon persists — run
agent-browser close explicitly to avoid orphaned processes
- networkidle unreliable on SPAs — prefer
wait --text "X" or wait --url "pattern"
- Timeout max 30s — keep
DEFAULT_TIMEOUT under 30000ms
- State files contain tokens — use
ENCRYPTION_KEY or add to .gitignore
- Shadow DOM not in snapshots — only light DOM visible
- Large pages — use
snapshot -i -c -d 3 to limit output size
- Chrome profile lock — close Chrome before using
--profile with same profile