agent-browser by jezweb/claude-skills
npx skills add https://github.com/jezweb/claude-skills --skill agent-browser每个浏览器自动化都遵循以下模式:
agent-browser open <url>agent-browser snapshot -i (获取元素引用,如 @e1, @e2)agent-browser open https://example.com/form
agent-browser snapshot -i
# 输出: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"
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 # 检查结果
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
命令可以在单个 shell 调用中使用 && 进行链式调用。浏览器通过后台守护进程在命令之间保持持久化,因此链式调用是安全的,并且比单独调用更高效。
# 在一个调用中链式执行打开 + 等待 + 快照
agent-browser open https://example.com && 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 wait --load networkidle && agent-browser screenshot page.png
何时使用链式调用: 当你在继续之前不需要读取中间命令的输出时(例如,打开 + 等待 + 截图),使用 &&。当你需要先解析输出时(例如,快照以发现引用,然后使用这些引用进行交互),请单独运行命令。
# 导航
agent-browser open <url> # 导航 (别名: goto, navigate)
agent-browser close # 关闭浏览器
# 快照
agent-browser snapshot -i # 带有引用的交互式元素 (推荐)
agent-browser snapshot -i -C # 包含光标交互式元素 (带有 onclick, cursor:pointer 的 div)
agent-browser snapshot -s "#selector" # 限定到 CSS 选择器
# 交互 (使用快照中的 @refs)
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 # 获取当前 URL
agent-browser get title # 获取页面标题
# 等待
agent-browser wait @e1 # 等待元素
agent-browser wait --load networkidle # 等待网络空闲
agent-browser wait --url "**/page" # 等待 URL 模式
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 screenshot # 截图到临时目录
agent-browser screenshot --full # 完整页面截图
agent-browser screenshot --annotate # 带有编号元素标签的标注截图
agent-browser pdf output.pdf # 保存为 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" # 限定到元素
agent-browser open https://example.com/signup
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
# 保存一次凭据 (使用 AGENT_BROWSER_ENCRYPTION_KEY 加密)
# 推荐:通过 stdin 管道传输密码以避免 shell 历史记录暴露
echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin
# 使用保存的配置文件登录 (LLM 永远不会看到密码)
agent-browser auth login github
# 列出/显示/删除配置文件
agent-browser auth list
agent-browser auth show github
agent-browser auth delete github
# 登录一次并保存状态
agent-browser open https://app.example.com/login
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
# 在浏览器重启时自动保存/恢复 cookies 和 localStorage
agent-browser --session-name myapp open https://app.example.com/login
# ... 登录流程 ...
agent-browser close # 状态自动保存到 ~/.agent-browser/sessions/
# 下次,状态会自动加载
agent-browser --session-name myapp open https://app.example.com/dashboard
# 静态加密状态
export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
agent-browser --session-name secure open https://app.example.com
# 管理保存的状态
agent-browser state list
agent-browser state show myapp-default.json
agent-browser state clear myapp
agent-browser state clean --older-than 7
agent-browser open https://example.com/products
agent-browser snapshot -i
agent-browser get text @e5 # 获取特定元素文本
agent-browser get text body > page.txt # 获取所有页面文本
# 用于解析的 JSON 输出
agent-browser snapshot -i --json
agent-browser get text @e1 --json
agent-browser --session site1 open https://site-a.com
agent-browser --session site2 open https://site-b.com
agent-browser --session site1 snapshot -i
agent-browser --session site2 snapshot -i
agent-browser session list
# 自动发现启用了远程调试的运行中的 Chrome
agent-browser --auto-connect open https://example.com
agent-browser --auto-connect snapshot
# 或者使用明确的 CDP 端口
agent-browser --cdp 9222 snapshot
# 通过标志启用持久深色模式 (适用于所有页面和新标签页)
agent-browser --color-scheme dark open https://example.com
# 或者通过环境变量
AGENT_BROWSER_COLOR_SCHEME=dark agent-browser open https://example.com
# 或者在会话期间设置 (对后续命令保持)
agent-browser set media dark
agent-browser --headed open https://example.com
agent-browser highlight @e1 # 高亮元素
agent-browser record start demo.webm # 录制会话
agent-browser profiler start # 启动 Chrome DevTools 性能分析
agent-browser profiler stop trace.json # 停止并保存性能分析文件 (路径可选)
# 使用 file:// URLs 打开本地文件
agent-browser --allow-file-access open file:///path/to/document.pdf
agent-browser --allow-file-access open file:///path/to/page.html
agent-browser screenshot output.png
# 列出可用的 iOS 模拟器
agent-browser device list
# 在特定设备上启动 Safari
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com
# 与桌面版相同的工作流 - 快照、交互、重新快照
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1 # 点击 (click 的别名)
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
要求: 安装有 Xcode 的 macOS,Appium (npm install -g appium && appium driver install xcuitest)
真实设备: 如果预先配置好,可与物理 iOS 设备配合使用。使用 --device "<UDID>",其中 UDID 来自 xcrun xctrace list devices。
所有安全功能都是可选的。默认情况下,agent-browser 对导航、操作或输出不施加任何限制。
启用 --content-boundaries 可以将页面来源的输出包装在标记中,以帮助 LLM 区分工具输出和不受信任的页面内容:
export AGENT_BROWSER_CONTENT_BOUNDARIES=1
agent-browser snapshot
# 输出:
# --- AGENT_BROWSER_PAGE_CONTENT nonce=<hex> origin=https://example.com ---
# [无障碍功能树]
# --- END_AGENT_BROWSER_PAGE_CONTENT nonce=<hex> ---
限制导航到受信任的域名。通配符如 *.example.com 也匹配裸域名 example.com。对非允许域名的子资源请求、WebSocket 和 EventSource 连接也会被阻止。请包含你的目标页面所依赖的 CDN 域名:
export AGENT_BROWSER_ALLOWED_DOMAINS="example.com,*.example.com"
agent-browser open https://example.com # 允许
agent-browser open https://malicious.com # 阻止
使用策略文件来控制破坏性操作:
export AGENT_BROWSER_ACTION_POLICY=./policy.json
示例 policy.json:
{"default": "deny", "allow": ["navigate", "snapshot", "click", "scroll", "wait", "get"]}
认证保险库操作 (auth login 等) 会绕过操作策略,但域名白名单仍然适用。
防止大型页面导致上下文泛滥:
export AGENT_BROWSER_MAX_OUTPUT=50000
在执行操作后使用 diff snapshot 来验证其是否产生了预期效果。这将比较当前的无障碍功能树与会话中上次拍摄的快照。
# 典型工作流:快照 -> 操作 -> 差异比较
agent-browser snapshot -i # 拍摄基线快照
agent-browser click @e2 # 执行操作
agent-browser diff snapshot # 查看更改内容 (自动与上次快照比较)
用于视觉回归测试或监控:
# 保存基线截图,稍后比较
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 输出使用 + 表示添加,- 表示删除,类似于 git diff。diff screenshot 生成一个差异图像,其中更改的像素以红色高亮显示,并附带一个不匹配百分比。
本地浏览器的默认 Playwright 超时时间为 25 秒。这可以通过 AGENT_BROWSER_DEFAULT_TIMEOUT 环境变量覆盖(值以毫秒为单位)。对于慢速网站或大型页面,请使用显式等待,而不是依赖默认超时:
# 等待网络活动稳定下来 (最适合慢速页面)
agent-browser wait --load networkidle
# 等待特定元素出现
agent-browser wait "#content"
agent-browser wait @e1
# 等待特定的 URL 模式 (重定向后很有用)
agent-browser wait --url "**/dashboard"
# 等待 JavaScript 条件
agent-browser wait --fn "document.readyState === 'complete'"
# 等待固定时长 (毫秒) 作为最后手段
agent-browser wait 5000
处理持续慢速的网站时,在 open 后使用 wait --load networkidle 以确保页面在拍摄快照前完全加载。如果特定元素渲染缓慢,请直接使用 wait <selector> 或 wait @ref 等待它。
当同时运行多个代理或自动化任务时,请始终使用命名会话以避免冲突:
# 每个代理获得自己独立的会话
agent-browser --session agent1 open site-a.com
agent-browser --session agent2 open site-b.com
# 检查活动会话
agent-browser session list
完成后始终关闭浏览器会话,以避免进程泄漏:
agent-browser close # 关闭默认会话
agent-browser --session agent1 close # 关闭特定会话
如果之前的会话没有正确关闭,守护进程可能仍在运行。在开始新工作之前,使用 agent-browser close 来清理它。
当页面发生变化时,引用 (@e1, @e2 等) 会失效。在以下操作后务必重新拍摄快照:
agent-browser click @e5 # 导航到新页面
agent-browser snapshot -i # 必须重新快照
agent-browser click @e1 # 使用新的引用
使用 --annotate 拍摄带有编号标签覆盖在交互式元素上的截图。每个标签 [N] 映射到引用 @eN。这还会缓存引用,因此你可以立即与元素交互,而无需单独的拍摄快照。
agent-browser screenshot --annotate
# 输出包括图像路径和图例:
# [1] @e1 button "Submit"
# [2] @e2 link "Home"
# [3] @e3 textbox "Email"
agent-browser click @e2 # 使用标注截图中的引用进行点击
在以下情况下使用标注截图:
当引用不可用或不可靠时,使用语义定位器:
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "user@test.com"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click
使用 eval 在浏览器上下文中运行 JavaScript。Shell 引用可能会破坏复杂的表达式 —— 使用 --stdin 或 -b 来避免问题。
# 简单表达式使用常规引用即可
agent-browser eval 'document.title'
agent-browser eval 'document.querySelectorAll("img").length'
# 复杂 JS:使用带有 heredoc 的 --stdin (推荐)
agent-browser eval --stdin <<'EVALEOF'
JSON.stringify(
Array.from(document.querySelectorAll("img"))
.filter(i => !i.alt)
.map(i => ({ src: i.src.split("/").pop(), width: i.width }))
)
EVALEOF
# 替代方案:base64 编码 (避免所有 shell 转义问题)
agent-browser eval -b "$(echo -n 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"
为什么这很重要: 当 shell 处理你的命令时,内部的双引号、! 字符(历史记录扩展)、反引号和 $() 都可能在 JavaScript 到达 agent-browser 之前破坏它。--stdin 和 -b 标志完全绕过了 shell 解释。
经验法则:
eval 'expression' 即可eval --stdin <<'EVALEOF'eval -b在项目根目录创建 agent-browser.json 以进行持久化设置:
{
"headed": true,
"proxy": "http://localhost:8080",
"profile": "./browser-data"
}
优先级 (从低到高):~/.agent-browser/config.json < ./agent-browser.json < 环境变量 < CLI 标志。使用 --config <path> 或 AGENT_BROWSER_CONFIG 环境变量指定自定义配置文件(如果缺失/无效则退出并报错)。所有 CLI 选项都映射到 camelCase 键(例如,--executable-path -> "executablePath")。布尔标志接受 true/false 值(例如,--headed false 会覆盖配置)。来自用户和项目配置的扩展会被合并,而不是替换。
| 参考 | 何时使用 |
|---|---|
| references/commands.md | 包含所有选项的完整命令参考 |
| references/snapshot-refs.md | 引用生命周期、失效规则、故障排除 |
| references/session-management.md | 并行会话、状态持久化、并发抓取 |
| references/authentication.md | 登录流程、OAuth、2FA 处理、状态重用 |
| references/video-recording.md | 用于调试和文档记录的录制工作流 |
| references/profiling.md | 用于性能分析的 Chrome DevTools 性能分析 |
| references/proxy-support.md | 代理配置、地理测试、轮换代理 |
| 模板 | 描述 |
|---|---|
| templates/form-automation.sh | 带验证的表单填写 |
| templates/authenticated-session.sh | 登录一次,重用状态 |
| templates/capture-workflow.sh | 带截图的内容提取 |
./templates/form-automation.sh https://example.com/form
./templates/authenticated-session.sh https://app.example.com/login
./templates/capture-workflow.sh https://example.com ./output
每周安装量
283
仓库
GitHub 星标数
643
首次出现
14 天前
安全审计
安装于
gemini-cli274
opencode274
github-copilot274
cline273
cursor273
codex273
Every browser automation follows this pattern:
agent-browser open <url>agent-browser snapshot -i (get element refs like @e1, @e2)agent-browser open https://example.com/form
agent-browser snapshot -i
# Output: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"
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 # Check result
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.
# Chain open + wait + snapshot in one call
agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser snapshot -i
# Chain multiple interactions
agent-browser fill @e1 "user@example.com" && agent-browser fill @e2 "password123" && agent-browser click @e3
# Navigate and capture
agent-browser open https://example.com && 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).
# Navigation
agent-browser open <url> # Navigate (aliases: goto, navigate)
agent-browser close # Close browser
# Snapshot
agent-browser snapshot -i # Interactive elements with refs (recommended)
agent-browser snapshot -i -C # Include cursor-interactive elements (divs with onclick, cursor:pointer)
agent-browser snapshot -s "#selector" # Scope to CSS selector
# Interaction (use @refs from snapshot)
agent-browser click @e1 # Click element
agent-browser click @e1 --new-tab # Click and open in new tab
agent-browser fill @e2 "text" # Clear and type text
agent-browser type @e2 "text" # Type without clearing
agent-browser select @e1 "option" # Select dropdown option
agent-browser check @e1 # Check checkbox
agent-browser press Enter # Press key
agent-browser keyboard type "text" # Type at current focus (no selector)
agent-browser keyboard inserttext "text" # Insert without key events
agent-browser scroll down 500 # Scroll page
agent-browser scroll down 500 --selector "div.content" # Scroll within a specific container
# Get information
agent-browser get text @e1 # Get element text
agent-browser get url # Get current URL
agent-browser get title # Get page title
# Wait
agent-browser wait @e1 # Wait for element
agent-browser wait --load networkidle # Wait for network idle
agent-browser wait --url "**/page" # Wait for URL pattern
agent-browser wait 2000 # Wait milliseconds
# Downloads
agent-browser download @e1 ./file.pdf # Click element to trigger download
agent-browser wait --download ./output.zip # Wait for any download to complete
agent-browser --download-path ./downloads open <url> # Set default download directory
# Capture
agent-browser screenshot # Screenshot to temp dir
agent-browser screenshot --full # Full page screenshot
agent-browser screenshot --annotate # Annotated screenshot with numbered element labels
agent-browser pdf output.pdf # Save as PDF
# Diff (compare page states)
agent-browser diff snapshot # Compare current vs last snapshot
agent-browser diff snapshot --baseline before.txt # Compare current vs saved file
agent-browser diff screenshot --baseline before.png # Visual pixel diff
agent-browser diff url <url1> <url2> # Compare two pages
agent-browser diff url <url1> <url2> --wait-until networkidle # Custom wait strategy
agent-browser diff url <url1> <url2> --selector "#main" # Scope to element
agent-browser open https://example.com/signup
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
# Save credentials once (encrypted with AGENT_BROWSER_ENCRYPTION_KEY)
# Recommended: pipe password via stdin to avoid shell history exposure
echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin
# Login using saved profile (LLM never sees password)
agent-browser auth login github
# List/show/delete profiles
agent-browser auth list
agent-browser auth show github
agent-browser auth delete github
# Login once and save state
agent-browser open https://app.example.com/login
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
# Reuse in future sessions
agent-browser state load auth.json
agent-browser open https://app.example.com/dashboard
# Auto-save/restore cookies and localStorage across browser restarts
agent-browser --session-name myapp open https://app.example.com/login
# ... login flow ...
agent-browser close # State auto-saved to ~/.agent-browser/sessions/
# Next time, state is auto-loaded
agent-browser --session-name myapp open https://app.example.com/dashboard
# Encrypt state at rest
export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
agent-browser --session-name secure open https://app.example.com
# Manage saved states
agent-browser state list
agent-browser state show myapp-default.json
agent-browser state clear myapp
agent-browser state clean --older-than 7
agent-browser open https://example.com/products
agent-browser snapshot -i
agent-browser get text @e5 # Get specific element text
agent-browser get text body > page.txt # Get all page text
# JSON output for parsing
agent-browser snapshot -i --json
agent-browser get text @e1 --json
agent-browser --session site1 open https://site-a.com
agent-browser --session site2 open https://site-b.com
agent-browser --session site1 snapshot -i
agent-browser --session site2 snapshot -i
agent-browser session list
# Auto-discover running Chrome with remote debugging enabled
agent-browser --auto-connect open https://example.com
agent-browser --auto-connect snapshot
# Or with explicit CDP port
agent-browser --cdp 9222 snapshot
# Persistent dark mode via flag (applies to all pages and new tabs)
agent-browser --color-scheme dark open https://example.com
# Or via environment variable
AGENT_BROWSER_COLOR_SCHEME=dark agent-browser open https://example.com
# Or set during session (persists for subsequent commands)
agent-browser set media dark
agent-browser --headed open https://example.com
agent-browser highlight @e1 # Highlight element
agent-browser record start demo.webm # Record session
agent-browser profiler start # Start Chrome DevTools profiling
agent-browser profiler stop trace.json # Stop and save profile (path optional)
# Open local files with file:// URLs
agent-browser --allow-file-access open file:///path/to/document.pdf
agent-browser --allow-file-access open file:///path/to/page.html
agent-browser screenshot output.png
# List available iOS simulators
agent-browser device list
# Launch Safari on a specific device
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com
# Same workflow as desktop - snapshot, interact, re-snapshot
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1 # Tap (alias for click)
agent-browser -p ios fill @e2 "text"
agent-browser -p ios swipe up # Mobile-specific gesture
# Take screenshot
agent-browser -p ios screenshot mobile.png
# Close session (shuts down simulator)
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.
All security features are opt-in. By default, agent-browser imposes no restrictions on navigation, actions, or output.
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
# Output:
# --- AGENT_BROWSER_PAGE_CONTENT nonce=<hex> origin=https://example.com ---
# [accessibility tree]
# --- END_AGENT_BROWSER_PAGE_CONTENT nonce=<hex> ---
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 # OK
agent-browser open https://malicious.com # Blocked
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.
Prevent context flooding from large pages:
export AGENT_BROWSER_MAX_OUTPUT=50000
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.
# Typical workflow: snapshot -> action -> diff
agent-browser snapshot -i # Take baseline snapshot
agent-browser click @e2 # Perform action
agent-browser diff snapshot # See what changed (auto-compares to last snapshot)
For visual regression testing or monitoring:
# Save a baseline screenshot, then compare later
agent-browser screenshot baseline.png
# ... time passes or changes are made ...
agent-browser diff screenshot --baseline baseline.png
# Compare staging vs production
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.
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:
# Wait for network activity to settle (best for slow pages)
agent-browser wait --load networkidle
# Wait for a specific element to appear
agent-browser wait "#content"
agent-browser wait @e1
# Wait for a specific URL pattern (useful after redirects)
agent-browser wait --url "**/dashboard"
# Wait for a JavaScript condition
agent-browser wait --fn "document.readyState === 'complete'"
# Wait a fixed duration (milliseconds) as a last resort
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.
When running multiple agents or automations concurrently, always use named sessions to avoid conflicts:
# Each agent gets its own isolated session
agent-browser --session agent1 open site-a.com
agent-browser --session agent2 open site-b.com
# Check active sessions
agent-browser session list
Always close your browser session when done to avoid leaked processes:
agent-browser close # Close default session
agent-browser --session agent1 close # Close specific session
If a previous session was not closed properly, the daemon may still be running. Use agent-browser close to clean it up before starting new work.
Refs (@e1, @e2, etc.) are invalidated when the page changes. Always re-snapshot after:
Clicking links or buttons that navigate
Form submissions
Dynamic content loading (dropdowns, modals)
agent-browser click @e5 # Navigates to new page agent-browser snapshot -i # MUST re-snapshot agent-browser click @e1 # Use new refs
Use --annotate to take a screenshot with numbered labels overlaid on interactive elements. Each label [N] maps to ref @eN. This also caches refs, so you can interact with elements immediately without a separate snapshot.
agent-browser screenshot --annotate
# Output includes the image path and a legend:
# [1] @e1 button "Submit"
# [2] @e2 link "Home"
# [3] @e3 textbox "Email"
agent-browser click @e2 # Click using ref from annotated screenshot
Use annotated screenshots when:
When refs are unavailable or unreliable, use semantic locators:
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "user@test.com"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click
Use eval to run JavaScript in the browser context. Shell quoting can corrupt complex expressions -- use --stdin or -b to avoid issues.
# Simple expressions work with regular quoting
agent-browser eval 'document.title'
agent-browser eval 'document.querySelectorAll("img").length'
# Complex JS: use --stdin with heredoc (RECOMMENDED)
agent-browser eval --stdin <<'EVALEOF'
JSON.stringify(
Array.from(document.querySelectorAll("img"))
.filter(i => !i.alt)
.map(i => ({ src: i.src.split("/").pop(), width: i.width }))
)
EVALEOF
# Alternative: base64 encoding (avoids all shell escaping issues)
agent-browser eval -b "$(echo -n 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"
Why this matters: When the shell processes your command, inner double quotes, ! characters (history expansion), backticks, and $() can all corrupt the JavaScript before it reaches agent-browser. The --stdin and -b flags bypass shell interpretation entirely.
Rules of thumb:
eval 'expression' with single quotes is fineeval --stdin <<'EVALEOF'eval -b with base64Create agent-browser.json in the project root for persistent settings:
{
"headed": true,
"proxy": "http://localhost:8080",
"profile": "./browser-data"
}
Priority (lowest to highest): ~/.agent-browser/config.json < ./agent-browser.json < env vars < CLI flags. Use --config <path> or AGENT_BROWSER_CONFIG env var for a custom config file (exits with error if missing/invalid). All CLI options map to camelCase keys (e.g., --executable-path -> "executablePath"). Boolean flags accept true/false values (e.g., --headed false overrides config). Extensions from user and project configs are merged, not replaced.
| Reference | When to Use |
|---|---|
| references/commands.md | Full command reference with all options |
| references/snapshot-refs.md | Ref lifecycle, invalidation rules, troubleshooting |
| references/session-management.md | Parallel sessions, state persistence, concurrent scraping |
| references/authentication.md | Login flows, OAuth, 2FA handling, state reuse |
| references/video-recording.md | Recording workflows for debugging and documentation |
| references/profiling.md | Chrome DevTools profiling for performance analysis |
| Template | Description |
|---|---|
| templates/form-automation.sh | Form filling with validation |
| templates/authenticated-session.sh | Login once, reuse state |
| templates/capture-workflow.sh | Content extraction with screenshots |
./templates/form-automation.sh https://example.com/form
./templates/authenticated-session.sh https://app.example.com/login
./templates/capture-workflow.sh https://example.com ./output
Weekly Installs
283
Repository
GitHub Stars
643
First Seen
14 days ago
Security Audits
Gen Agent Trust HubPassSocketWarnSnykFail
Installed on
gemini-cli274
opencode274
github-copilot274
cline273
cursor273
codex273
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
27,400 周安装
| Proxy configuration, geo-testing, rotating proxies |