| name | agent-browser |
| description | 真实浏览器自动化操作工具,支持操控真实的浏览器实例(非模拟器),满足用户在真实浏览器环境下的各类操作需求。核心能力包括:网页导航与页面访问、表单填写与提交、按钮点击与元素交互、页面截图与全页面截图、网页数据抓取与内容提取、Web 应用自动化测试、登录认证(支持用户接管模式,适用于扫码登录、短信验证等需要人工介入的场景)、支付等敏感操作的安全处理。当用户提出以下需求时应使用此工具:「打开某个网站」、「填写表单」、「点击按钮」、「截图」、「抓取页面数据」、「测试这个网页」、「登录某个网站」、「自动化浏览器操作」、「帮我在网页上完成某个操作」,或任何需要在真实浏览器中执行的交互任务。支持多会话并行、状态持久化、设备模拟、视觉对比等高级功能。 |
| allowed-tools | Bash(agent-browser:*), browser_wait_user_action, sessions_spawn |
Browser Automation with agent-browser
Agent Guidelines & Restrictions
- NO Command Line Output to User: Do NOT output any terminal commands (like
agent-browser ...) to the user. The user cannot execute these commands. If you need the user to make a choice or provide input, use clear, natural language to ask them.
- Sensitive Operations & User Takeover (IMPORTANT): When encountering sensitive operations such as login, authentication, or payment, you must call the
browser_wait_user_action tool to trigger the user takeover flow. After successfully calling this tool, inform the user that their manual action is required. The user will notify you once they have completed (or cancelled) the operation, after which you can continue the automation. You are no longer restricted to using only QR code login.
During task execution, pause and wait for user completion before continuing when any of the following actions are required:
- Entering passwords, verification codes, or fingerprint authentication
- Confirming payments, transfers, or subscription charges
- Permanently deleting data or deactivating/closing accounts
- Changing passwords or security settings
- Registering a new account
- Granting sensitive permissions (contacts, location, microphone, etc.)
- Screenshots: When capturing screenshots, ALL screenshot files MUST be saved to the
/app/data/所有对话/主对话/browser/screenshots/ directory. For different tasks, you should create separate subdirectories under this directory to store screenshots independently. Please ensure that the directory structure is clear and easy to understand (e.g., agent-browser screenshot /app/data/所有对话/主对话/browser/screenshots/task_name/page.png).
- Background Execution(Sub Session): When using this skill, try to execute tasks in the background as much as possible. You can create a background session via using
sessions_spawn. CRITICAL: The sub-session MUST report the execution status of the current task back to the main session, and explicitly state whether browser_wait_user_action has been called. If this tool has already been called, do NOT call it repeatedly.
- Profile Lock Resolution: If you encounter an error indicating that the profile file is locked, you can try deleting the
$AGENT_BROWSER_PROFILE/Singleton* lock files.
Core Workflow
Every browser automation follows this pattern:
- Navigate:
agent-browser open <url> && agent-browser tab 0
- Snapshot:
agent-browser snapshot -i (get element refs like @e1, @e2)
- Interact: Use refs to click, fill, select
- Re-snapshot: After navigation or DOM changes, get fresh refs
agent-browser open https://example.com/form && agent-browser tab 0
agent-browser snapshot -i
agent-browser fill @e1 "user@example.com"
agent-browser fill @e2 "password123"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i
Command Chaining
Commands can be chained with && in a single shell invocation. The browser persists between commands via a background daemon, so chaining is safe and more efficient than separate calls.
agent-browser open https://example.com && agent-browser tab 0 && agent-browser wait --load networkidle && agent-browser snapshot -i
agent-browser fill @e1 "user@example.com" && agent-browser fill @e2 "password123" && agent-browser click @e3
agent-browser open https://example.com && agent-browser tab 0 && agent-browser wait --load networkidle && agent-browser screenshot page.png
When to chain: Use && when you don't need to read the output of an intermediate command before proceeding (e.g., open + wait + screenshot). Run commands separately when you need to parse the output first (e.g., snapshot to discover refs, then interact using those refs).
Essential Commands
agent-browser open <url> && agent-browser tab 0
agent-browser close
agent-browser snapshot -i
agent-browser snapshot -i -C
agent-browser snapshot -s "#selector"
agent-browser click @e1
agent-browser click @e1 --new-tab
agent-browser fill @e2 "text"
agent-browser type @e2 "text"
agent-browser select @e1 "option"
agent-browser check @e1
agent-browser press Enter
agent-browser keyboard type "text"
agent-browser keyboard inserttext "text"
agent-browser scroll down 500
agent-browser scroll down 500 --selector "div.content"
agent-browser get text @e1
agent-browser get url
agent-browser get title
agent-browser wait @e1
agent-browser wait --load networkidle
agent-browser wait --url "**/page"
agent-browser wait 2000
agent-browser download @e1 ./file.pdf
agent-browser wait --download ./output.zip
agent-browser --download-path ./downloads open <url> && agent-browser --download-path ./downloads tab 0
agent-browser set viewport 1920 1080
agent-browser set viewport 1920 1080 2
agent-browser set device "iPhone 14"
agent-browser screenshot
agent-browser screenshot --full
agent-browser screenshot --annotate
agent-browser pdf output.pdf
agent-browser diff snapshot
agent-browser diff snapshot --baseline before.txt
agent-browser diff screenshot --baseline before.png
agent-browser diff url <url1> <url2>
agent-browser diff url <url1> <url2> --wait-until networkidle
agent-browser diff url <url1> <url2> --selector "#main"
Common Patterns
Form Submission
agent-browser open https://example.com/signup && agent-browser tab 0
agent-browser snapshot -i
agent-browser fill @e1 "Jane Doe"
agent-browser fill @e2 "jane@example.com"
agent-browser select @e3 "California"
agent-browser check @e4
agent-browser click @e5
agent-browser wait --load networkidle
Authentication with Auth Vault (Recommended)
echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin
agent-browser auth login github
agent-browser auth list
agent-browser auth show github
agent-browser auth delete github
Authentication with State Persistence
agent-browser open https://app.example.com/login && agent-browser tab 0
agent-browser snapshot -i
agent-browser fill @e1 "$USERNAME"
agent-browser fill @e2 "$PASSWORD"
agent-browser click @e3
agent-browser wait --url "**/dashboard"
agent-browser state save auth.json
agent-browser state load auth.json
agent-browser open https://app.example.com/dashboard && agent-browser tab 0
Session Persistence
agent-browser --session-name myapp open https://app.example.com/login && agent-browser --session-name myapp tab 0
agent-browser close
agent-browser --session-name myapp open https://app.example.com/dashboard && agent-browser --session-name myapp tab 0
export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
agent-browser --session-name secure open https://app.example.com && agent-browser --session-name secure tab 0
agent-browser state list
agent-browser state show myapp-default.json
agent-browser state clear myapp
agent-browser state clean --older-than 7
Data Extraction
agent-browser open https://example.com/products && agent-browser tab 0
agent-browser snapshot -i
agent-browser get text @e5
agent-browser get text body > page.txt
agent-browser snapshot -i --json
agent-browser get text @e1 --json
Parallel Sessions
agent-browser --session site1 open https://site-a.com && agent-browser --session site1 tab 0
agent-browser --session site2 open https://site-b.com && agent-browser --session site2 tab 0
agent-browser --session site1 snapshot -i
agent-browser --session site2 snapshot -i
agent-browser session list
Connect to Existing Chrome
agent-browser --auto-connect open https://example.com && agent-browser --auto-connect tab 0
agent-browser --auto-connect snapshot
agent-browser --cdp 9222 snapshot
Color Scheme (Dark Mode)
agent-browser --color-scheme dark open https://example.com && agent-browser --color-scheme dark tab 0
AGENT_BROWSER_COLOR_SCHEME=dark agent-browser open https://example.com && agent-browser tab 0
agent-browser set media dark
Viewport & Responsive Testing
agent-browser set viewport 1920 1080
agent-browser screenshot desktop.png
agent-browser set viewport 375 812
agent-browser screenshot mobile.png
agent-browser set viewport 1920 1080 2
agent-browser screenshot retina.png
agent-browser set device "iPhone 14"
agent-browser screenshot device.png
The scale parameter (3rd argument) sets window.devicePixelRatio without changing CSS layout. Use it when testing retina rendering or capturing higher-resolution screenshots.
Visual Browser (Debugging)
agent-browser --headed open https://example.com && agent-browser --headed tab 0
agent-browser highlight @e1
agent-browser record start demo.webm
agent-browser profiler start
agent-browser profiler stop trace.json
Use AGENT_BROWSER_HEADED=1 to enable headed mode via environment variable. Browser extensions work in both headed and headless mode.
Local Files (PDFs, HTML)
agent-browser --allow-file-access open file:///path/to/document.pdf && agent-browser --allow-file-access tab 0
agent-browser --allow-file-access open file:///path/to/page.html && agent-browser --allow-file-access tab 0
agent-browser screenshot output.png
iOS Simulator (Mobile Safari)
agent-browser device list
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com && agent-browser -p ios --device "iPhone 16 Pro" tab 0
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1
agent-browser -p ios fill @e2 "text"
agent-browser -p ios swipe up
agent-browser -p ios screenshot mobile.png
agent-browser -p ios close
Requirements: macOS with Xcode, Appium (npm install -g appium && appium driver install xcuitest)
Real devices: Works with physical iOS devices if pre-configured. Use --device "<UDID>" where UDID is from xcrun xctrace list devices.
Security
All security features are opt-in. By default, agent-browser imposes no restrictions on navigation, actions, or output.
Content Boundaries (Recommended for AI Agents)
Enable --content-boundaries to wrap page-sourced output in markers that help LLMs distinguish tool output from untrusted page content:
export AGENT_BROWSER_CONTENT_BOUNDARIES=1
agent-browser snapshot
Domain Allowlist
Restrict navigation to trusted domains. Wildcards like *.example.com also match the bare domain example.com. Sub-resource requests, WebSocket, and EventSource connections to non-allowed domains are also blocked. Include CDN domains your target pages depend on:
export AGENT_BROWSER_ALLOWED_DOMAINS="example.com,*.example.com"
agent-browser open https://example.com && agent-browser tab 0
agent-browser open https://malicious.com && agent-browser tab 0
Action Policy
Use a policy file to gate destructive actions:
export AGENT_BROWSER_ACTION_POLICY=./policy.json
Example policy.json:
{"default": "deny", "allow": ["navigate", "snapshot", "click", "scroll", "wait", "get"]}
Auth vault operations (auth login, etc.) bypass action policy but domain allowlist still applies.
Output Limits
Prevent context flooding from large pages:
export AGENT_BROWSER_MAX_OUTPUT=50000
Diffing (Verifying Changes)
Use diff snapshot after performing an action to verify it had the intended effect. This compares the current accessibility tree against the last snapshot taken in the session.
agent-browser snapshot -i
agent-browser click @e2
agent-browser diff snapshot
For visual regression testing or monitoring:
agent-browser screenshot baseline.png
agent-browser diff screenshot --baseline baseline.png
agent-browser diff url https://staging.example.com https://prod.example.com --screenshot
diff snapshot output uses + for additions and - for removals, similar to git diff. diff screenshot produces a diff image with changed pixels highlighted in red, plus a mismatch percentage.
Timeouts and Slow Pages
The default Playwright timeout is 25 seconds for local browsers. This can be overridden with the AGENT_BROWSER_DEFAULT_TIMEOUT environment variable (value in milliseconds). For slow websites or large pages, use explicit waits instead of relying on the default timeout:
agent-browser wait --load networkidle
agent-browser wait "#content"
agent-browser wait @e1
agent-browser wait --url "**/dashboard"
agent-browser wait --fn "document.readyState === 'complete'"
agent-browser wait 5000
When dealing with consistently slow websites, use wait --load networkidle after open to ensure the page is fully loaded before taking a snapshot. If a specific element is slow to render, wait for it directly with wait <selector> or wait @ref.