| name | agent-browser-loop |
| description | Use when an agent must drive a live browser session in a back-and-forth loop (state -> explicit actions -> state) for UI validation, reproducible QA, or debugging UI behavior. Prefer this over one-shot CLI usage when an agent needs inspectable, stepwise control. |
Agent Browser Loop
Control a browser via CLI. Execute actions, read state, and verify UI changes in a stepwise loop.
Quick Start
TIP: Check package.json for dev server scripts to find the port to test
agent-browser open http://localhost:3000
agent-browser act click:button_0
agent-browser wait --text "Success"
agent-browser state
agent-browser close
Use --headed to see the browser: agent-browser open http://localhost:3000 --headed
Core Loop
- Open:
agent-browser open <url> - starts daemon, navigates to URL
- Act:
agent-browser act <actions...> - interact with elements
- Wait:
agent-browser wait --text/--selector/--url - wait for conditions
- State:
agent-browser state - read current page state
- Repeat until task complete
- Close:
agent-browser close - stop browser daemon
Commands
| Command | Purpose |
|---|
open <url> | Open URL (starts daemon if needed) |
act <actions...> | Execute actions |
wait | Wait for conditions |
state | Get current page state |
screenshot | Capture screenshot |
close | Close browser and daemon |
status | Check if daemon is running |
Action Syntax
Actions use format action:target or action:target:value:
agent-browser act navigate:http://localhost:3000
agent-browser act click:button_0
agent-browser act click:link_2
agent-browser act type:input_0:hello
agent-browser act type:input_1:"text with spaces"
agent-browser act press:Enter
agent-browser act press:Tab
agent-browser act scroll:down
agent-browser act scroll:up:500
agent-browser act click:input_0 type:input_0:hello press:Enter
Wait Conditions
agent-browser wait --text "Welcome"
agent-browser wait --selector "#success"
agent-browser wait --url "/dashboard"
agent-browser wait --not-text "Loading..."
agent-browser wait --not-selector ".spinner"
agent-browser wait --text "Done" --timeout 60000
Element References
State includes interactive elements with stable refs:
Interactive Elements:
[0] ref=input_0 textbox "Email" (placeholder="Enter email")
[1] ref=input_1 textbox "Password" (type="password")
[2] ref=button_0 button "Sign In"
[3] ref=link_0 link "Forgot password?" (href="/forgot")
Use ref values in actions: click:button_0, type:input_0:hello
Refs are type-prefixed (button_, input_, link_, checkbox_, select_) and stable within a session.
Reading State
State includes:
- Current URL and title
- Scroll position
- Interactive elements with values
- Console and network errors
URL: http://localhost:3000/login
Title: Login
Tabs: 1
Scroll: 0px above, 500px below
Interactive Elements:
[0] ref=input_0 textbox "Email" value="user@test.com"
[1] ref=input_1 textbox "Password" (type="password")
[2] ref=checkbox_0 checkbox "Remember me" (checked="true")
[3] ref=button_0 button "Sign In"
Errors:
Console:
- [error] Failed to load resource: 404
Network:
- 404 GET /api/user
Complete Example: Login Flow
agent-browser open http://localhost:3000/login
agent-browser act \
type:input_0:user@example.com \
type:input_1:password123 \
click:button_0
agent-browser wait --text "Welcome" --timeout 5000
agent-browser state
agent-browser close
Options
agent-browser open http://localhost:3000 --headed
agent-browser open http://localhost:3000 --width 1920 --height 1080
agent-browser resize 1920 1080
Profiles (Session Storage)
Save and reuse cookies/localStorage across sessions. The profile name (e.g., admin, testuser) is an arbitrary identifier you choose.
agent-browser profile capture admin --url http://localhost:3000/login
agent-browser open http://localhost:3000/login --headed
agent-browser profile save admin
agent-browser open http://localhost:3000/dashboard --profile admin
agent-browser close
agent-browser open http://localhost:3000 --profile admin --no-save
agent-browser profile list
agent-browser profile show admin
agent-browser profile delete admin
Profiles are stored locally (.agent-browser/profiles/) or globally (~/.config/agent-browser/profiles/).
Multi-Session
Run multiple browsers in parallel with --new:
agent-browser open --new http://localhost:3000
agent-browser open --new http://localhost:3000
agent-browser act -s swift-fox click:button_0
agent-browser sessions
agent-browser close -s swift-fox
agent-browser close --all
Screenshots
agent-browser screenshot -o screenshot.png
agent-browser screenshot --full-page -o full.png
agent-browser screenshot
Use when text state isn't enough to diagnose visual issues.
Debugging Tips
- Action does nothing? Check errors in state output
- Element not found? Run
agent-browser state to see current refs
- Waiting times out? Check exact text/selector, try simpler condition
- Need visual check? Use
--headed or agent-browser screenshot
- Refs changed? DOM updates can change refs - re-fetch state
HTTP Server Mode
For multi-session scenarios or HTTP-based integrations:
agent-browser server --headed
Full Reference
See REFERENCE.md for complete CLI documentation.