AI-Optimized Browser Automation with agent-browser
Vercel's agent-browser — a Rust-native CLI built on Playwright, optimized for AI agents with semantic locators and accessibility-first snapshots.
Quick Start
# Install (if not already)
npm install -g agent-browser
agent-browser install # Downloads Chrome for Testing
# Basic session
agent-browser open https://example.com
agent-browser snapshot # Accessibility tree with element refs
agent-browser click @e2 # Click by ref
agent-browser fill @e3 "query" # Fill input
agent-browser screenshot page.png
agent-browser close
When to Use (vs playwright-cli)
Use agent-browser when:
- You need semantic element targeting (by role, label, text — not CSS selectors)
- The page structure is complex and CSS selectors are fragile
- You want accessibility-tree-based snapshots optimized for AI parsing
Use playwright-cli instead for:
- General browser automation (it's the default)
- Network interception and mocking
- Tracing and video recording
- Cookie/storage management
Commands
Navigation & Interaction
agent-browser open https://example.com
agent-browser click @e5
agent-browser dblclick @e7
agent-browser hover @e3
agent-browser focus @e4
agent-browser fill @e2 "user@example.com"
agent-browser type "search query"
agent-browser press Enter
agent-browser scroll down
agent-browser drag @e1 @e8
agent-browser upload ./file.pdf
Semantic Locators (key differentiator)
# Find by ARIA role
agent-browser find role button click --name "Submit"
# Find by visible text
agent-browser find text "Sign In" click
# Find by label
agent-browser find label "Email" fill "test@example.com"
# Find by placeholder
agent-browser find placeholder "Search..." fill "query"
Information Retrieval
agent-browser snapshot # Full accessibility tree
agent-browser get text @e5 # Element text content
agent-browser get html @e5 # Element HTML
agent-browser get value @e3 # Input value
agent-browser get attr href @e5 # Element attribute
agent-browser screenshot page.png
agent-browser pdf output.pdf
State Checks
agent-browser wait @e5 # Wait for element visible
agent-browser is visible @e5
agent-browser is enabled @e3
agent-browser is checked @e8
Network & Debugging
agent-browser network route "**/*.jpg" --status=404
agent-browser network requests # View tracked requests
agent-browser eval "document.title"
Session Management
agent-browser cookies list
agent-browser cookies get session_id
agent-browser storage get theme
agent-browser close
Batch Execution
Pipe JSON command arrays for reduced process startup overhead:
echo '[{"cmd":"open","args":["https://example.com"]},{"cmd":"snapshot"}]' | agent-browser batch
Key Advantages
- Native Rust binary — fast startup, no Node.js runtime for daemon
- Accessibility-first snapshots — semantic tree optimized for AI agents
- Stateful sessions — browser state persists across commands
- Semantic locators — find elements by role, label, text instead of CSS