| name | agent-browser |
| description | Headless browser automation for AI agents using agent-browser CLI. Use when Claude needs to automate web browsing, scrape web data, interact with web pages, fill forms, take screenshots, or perform any browser-based tasks. Supports reference-based element targeting, session management, and semantic locators. |
| disable-model-invocation | true |
Agent Browser Automation
Guide for using agent-browser CLI to automate web browsing tasks in Claude Code.
Quick Start
Installation Check
Before using agent-browser, verify installation:
agent-browser --version
npm install -g agent-browser
agent-browser install
Windows Note: If you encounter /bin/sh errors on Windows, use:
npx agent-browser <command>
See troubleshooting.md for platform-specific issues.
Core Workflow
agent-browser uses a refs-based system where page elements get unique identifiers (like @e1, @e2) that you can use for interactions.
Basic Pattern
- Open a page
- Get snapshot with refs
- Interact using refs
- Repeat as needed
agent-browser open example.com
agent-browser snapshot -i --json
agent-browser click @e5
agent-browser fill @e3 "search query"
agent-browser screenshot result.png
Essential Commands
Navigation
agent-browser open <url>
agent-browser goto <url>
agent-browser back
agent-browser forward
agent-browser reload
Getting Page Information
agent-browser snapshot
agent-browser snapshot -i
agent-browser snapshot -i --json
agent-browser screenshot <file>
agent-browser get text @e1
agent-browser get html
agent-browser get url
Interacting with Elements
agent-browser click @e2
agent-browser dblclick @e2
agent-browser fill @e3 "text"
agent-browser type @e3 "text"
agent-browser press Enter
agent-browser check @e4
agent-browser select @e5 "option"
agent-browser upload @e6 file.pdf
Semantic Locators (Find Commands)
When you don't have refs, use semantic locators:
agent-browser find role button click --name "Submit"
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "user@example.com"
agent-browser find placeholder "Search..." type "query"
Waiting
agent-browser wait @e1
agent-browser wait --text "Done"
agent-browser wait --url /success
agent-browser wait --load
Session Management
Use sessions to run multiple isolated browser instances:
agent-browser --session task1 open site-a.com
agent-browser --session task2 open site-b.com
agent-browser session list
agent-browser --session task1 close
AI Agent Workflow
For AI-driven automation, follow this pattern:
- Navigate and snapshot
agent-browser open https://example.com
agent-browser snapshot -i --json > page.json
-
Parse JSON to understand page structure
- Identify interactive elements and their refs
- Understand page layout and available actions
-
Execute actions using refs
agent-browser click @e2
agent-browser fill @e5 "input data"
- Get new snapshot after page changes
agent-browser snapshot -i --json > updated.json
- Repeat until task complete
See workflows.md for detailed AI workflow patterns.
Advanced Features
Network Interception
agent-browser route --block "*.ads.com/*"
agent-browser route --mock "/api/data" response.json
State Persistence
agent-browser save-state auth.json
agent-browser load-state auth.json
Debugging
agent-browser --console open example.com
agent-browser highlight @e3
agent-browser --trace trace.zip open example.com
Best Practices
- Use
-i --json for snapshots - Reduces noise, easier for AI to parse
- Prefer refs over selectors - More reliable than CSS/XPath
- Use sessions for parallel tasks - Isolate different workflows
- Wait for elements - Use
wait commands to handle dynamic content
- Take screenshots - Visual confirmation of state
- Use semantic locators as fallback - When refs aren't available
Common Patterns
Form Filling
agent-browser open https://form.example.com
agent-browser snapshot -i --json
agent-browser fill @e1 "John Doe"
agent-browser fill @e2 "john@example.com"
agent-browser click @e3
agent-browser wait --url /success
Data Extraction
agent-browser open https://data.example.com
agent-browser snapshot -i --json > structure.json
agent-browser get text @e5 > data.txt
agent-browser screenshot evidence.png
Multi-Step Workflow
agent-browser open https://app.example.com/login
agent-browser fill @e1 "username"
agent-browser fill @e2 "password"
agent-browser click @e3
agent-browser wait --url /dashboard
agent-browser goto https://app.example.com/data
agent-browser snapshot -i --json > results.json
Platform-Specific Notes
Windows
- Use
npx agent-browser if global command fails
- PowerShell may require quotes around URLs with special characters
- See troubleshooting.md for
/bin/sh errors
Linux
- Install with dependencies:
agent-browser install --with-deps
- May need to install Playwright system dependencies manually
macOS
- Works out of the box after
npm install -g agent-browser
Reference Documentation
Architecture
agent-browser is built on Playwright with:
- Fast Rust CLI implementation (with Node.js fallback)
- Accessibility tree parsing for AI-friendly page representation
- Reference system (
@e1, @e2) for stable element targeting
- Chrome DevTools Protocol (CDP) for persistent sessions
When to Use agent-browser
✅ Use agent-browser when:
- Automating web browsing tasks
- Scraping data from websites
- Filling and submitting forms
- Testing web applications
- Interacting with dynamic web pages
- Need AI-friendly element targeting
❌ Don't use agent-browser when:
- Simple HTTP requests suffice (use curl/fetch instead)
- API endpoints are available (use API directly)
- Task doesn't require browser rendering