Agent Browser Skill
Headless browser automation using Playwright Python. Provides accessibility tree snapshots with @e# element references for deterministic interaction, screenshot capture, form filling, and multi-command execution sequences.
Quick Start
Scrape page content (prints to stdout, saves to output/):
python skills/agent-browser/scripts/browse.py \
--operation scrape \
--url "https://example.com"
With a custom output directory:
python skills/agent-browser/scripts/browse.py \
--output-dir output \
--operation screenshot \
--url "https://example.com" \
--full-page
Supported Operations
| Operation | Description | Key Parameters |
|---|---|---|
scrape |
Open page and get accessibility tree | --url |
screenshot |
Capture page screenshot | --url, --full-page |
snapshot |
Get element refs for interaction | --url, --interactive |
click |
Click an element | --url, --selector |
fill |
Fill a form input | --url, --selector, --text |
type |
Type text character by character | --url, --selector, --text |
execute |
Run arbitrary command sequences | --commands (JSON array) |
Parameters
| Parameter | Required | Default | Description |
|---|---|---|---|
--operation |
Yes | - | Operation type (see table above) |
--url |
Depends | - | Target URL (required for most operations) |
--output-dir |
No | output |
Directory to save output files (defaults to ./output/) |
--selector |
Depends | - | Element selector (@e1, CSS, or XPath) |
--text |
Depends | - | Text to fill/type |
--commands |
Depends | - | JSON array of commands for execute operation |
--full-page |
No | false | Full page screenshot |
--interactive |
No | false | Interactive elements only in snapshot |
--timeout |
No | 30000 | Command timeout in ms |
--profile |
No | - | Browser profile name for authenticated sessions (loads cookies from ./browser-profiles/<name>/) |
Output Location
Results are always printed to stdout as JSON. For scrape, snapshot, execute, and screenshot operations, output files are also saved to ./output/ by default, or to the directory given by --output-dir.
Snapshot and Element References
The snapshot command returns an accessibility tree with @e# element references:
python skills/agent-browser/scripts/browse.py \
--operation snapshot --url "https://httpbin.org/forms/post" --interactive
Output (in the snapshot field of the JSON response):
[@e1] [textbox] Customer name:
[@e2] [textbox] Telephone:
[@e3] [textbox] E-mail address:
[@e4] [radio] Small
[@e5] [radio] Medium
[@e6] [radio] Large
[@e7] [checkbox] Bacon
[@e8] [checkbox] Extra Cheese
[@e11] [textbox] Preferred delivery time:
[@e12] [textbox] Delivery instructions:
[@e13] [button] Submit order
Use these refs in the execute operation for deterministic element interaction.
Important: @e# refs only persist within a single execute session. Each separate scrape/snapshot call launches a new browser, so refs from one call cannot be used in another. For multi-step workflows, always use the execute operation.
Standard Workflow Pattern
Most browser automation follows this pattern using the execute operation:
1. Open URL → open <url>
2. Get snapshot → snapshot -i
3. Interact → click/fill/type @e#
4. Wait (if needed) → wait --load
5. Capture result → screenshot
Example: Form Submission via Execute
python skills/agent-browser/scripts/browse.py \
--operation execute \
--commands '[
{"cmd": "open", "args": ["https://example.com/login"]},
{"cmd": "wait", "args": ["--load"]},
{"cmd": "snapshot", "args": ["-i"]},
{"cmd": "fill", "args": ["@e1", "myuser"]},
{"cmd": "fill", "args": ["@e2", "mypassword"]},
{"cmd": "click", "args": ["@e3"]},
{"cmd": "wait", "args": ["--load"]},
{"cmd": "screenshot", "args": ["result.png"]}
]'
Execute Command Reference
The execute operation runs a sequence of commands in a single browser session. Each command is {"cmd": "<name>", "args": [...]}.
Navigation
| Command | Args | Description |
|---|---|---|
open |
[url] |
Navigate to URL |
back |
[] |
Go back in history |
forward |
[] |
Go forward in history |
reload |
[] |
Reload current page |
Element Interaction
| Command | Args | Description |
|---|---|---|
click |
[selector] |
Click element |
dblclick |
[selector] |
Double-click element |
fill |
[selector, text] |
Clear and fill input |
type |
[selector, text] |
Type character by character |
press |
[key] |
Press keyboard key (Enter, Tab, etc.) |
hover |
[selector] |
Hover over element |
check |
[selector] |
Check checkbox |
uncheck |
[selector] |
Uncheck checkbox |
select |
[selector, value] |
Select dropdown option |
scroll |
[direction, pixels] |
Scroll (up/down/left/right) |
Information Retrieval
| Command | Args | Description |
|---|---|---|
get |
["title"] |
Get page title |
get |
["url"] |
Get current URL |
get |
["text", selector] |
Get element text content |
get |
["html", selector] |
Get element innerHTML |
get |
["value", selector] |
Get input value |
get |
["attr", selector, attr] |
Get element attribute |
get |
["count", selector] |
Count matching elements |
Snapshots and Screenshots
| Command | Args | Description |
|---|---|---|
snapshot |
[] or ["-i"] |
Accessibility tree (with -i for interactive only) |
screenshot |
[path] or [path, "--full"] |
Capture screenshot |
pdf |
[path] |
Save page as PDF |
Waiting
| Command | Args | Description |
|---|---|---|
wait |
["--load"] |
Wait for page load |
wait |
["--load", "networkidle"] |
Wait for network idle |
wait |
["--text", "Success"] |
Wait for text to appear |
wait |
["--url", "/dashboard"] |
Wait for URL match |
wait |
["2000"] |
Wait milliseconds |
wait |
[".selector"] |
Wait for element |
JavaScript
| Command | Args | Description |
|---|---|---|
eval |
[js_expression] |
Execute JavaScript |
Selector Types
- @e# refs: From snapshot output (e.g.,
@e1,@e2) -- must runsnapshotfirst within the sameexecutesession - CSS selectors: Standard CSS (e.g.,
#submit,.btn-primary) - XPath: XPath expressions (e.g.,
//button[@type="submit"])
Authenticated Sessions
Use the --profile flag to load a persistent browser profile with saved cookies and login state. Profiles are managed with the browser-profile skill.
Setup (one-time):
python skills/browser-profile/scripts/manage.py \
--operation create --name sistrix --url "https://www.sistrix.com/"
Usage in automation:
python skills/agent-browser/scripts/browse.py \
--operation scrape \
--url "https://app.sistrix.com/visibility-index/example.com" \
--profile sistrix
Without --profile, the browser runs in ephemeral mode (no cookies, no session persistence).
Output Format
All operations return JSON to stdout. For scrape and snapshot operations, the accessibility tree is included in the snapshot field so agents can read it without opening saved files.
{
"success": true,
"operation": "scrape",
"output_file": "output/browser_scrape_20250123T1430.json",
"summary": "Scraped https://example.com - 3 elements found",
"snapshot": "[@e1] [link] More information...\n...",
"stats": {
"url": "https://example.com",
"element_count": 3,
"interactive_count": 3
}
}
For execute, per-step results are included in the results array.
Error Handling
Errors are returned as JSON to stdout (not stderr) so agents always see them:
{
"success": false,
"error": "Click failed: Timeout 30000ms exceeded",
"operation": "click"
}
- Navigation failures: Returns error with details
- Timeout: Commands timeout after specified duration (default 30s)
- Element not found: Returns descriptive error with selector info
- Execute chain: Stops on first error (except for wait/close)
Prerequisites
Playwright Python with Chromium browser:
pip install playwright
playwright install chromium
Comparison with claude-chrome
| Feature | agent-browser | agent-browser + profile | claude-chrome |
|---|---|---|---|
| Engine | Playwright (Python) | Playwright (Python) | Chrome with extension |
| Authentication | No persistent auth | Persistent via --profile | Uses Chrome login state |
| Element selection | @e# refs from snapshot | @e# refs from snapshot | Visual + CSS selectors |
| Best for | Automation, scraping | Authenticated scraping | Interactive debugging |
| Requires Chrome | No | No | Yes |
Resources
scripts/
browse.py- Main Python wrapper using Playwright