关于 agent-browser
agent-browser 是通过命令行自动化 Chrome/Chromium 的浏览器工具,面向需要执行网页交互或采集页面信息的 Agent。它提供可复用会话、认证状态管理、批量命令及页面快照交互。
主要功能
- 01通过 CDP 控制 Chrome/Chromium
- 02快照定位元素并执行交互
- 03保存与恢复认证及会话状态
- 04批量运行浏览器命令
- 05截图、提取文本并支持多会话
适用场景
- 01自动填写并提交网页表单
- 02复用登录状态访问站点
- 03提取网页文本或截图
- 04并行操作多个浏览器会话
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ julianromli/ ai-skills --skill agent-browser安装后在 Claude Code 中输入/agent-browser确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/authentication.mdcommands.mdprofiling.mdproxy-support.mdsession-management.mdsnapshot-refs.mdvideo-recording.mdtemplates/authenticated-session.shcapture-workflow.shform-automation.sh详细介绍
使用 agent-browser 进行浏览器自动化
此 CLI 通过 CDP 直接使用 Chrome/Chromium。可通过 npm i -g agent-browser、brew install agent-browser 或 cargo install agent-browser 安装。运行 agent-browser install 下载 Chrome。运行 agent-browser upgrade 更新到最新版本。
核心工作流
每次浏览器自动化都遵循以下模式:
- 导航:
agent-browser open <url> - 快照:
agent-browser snapshot -i(获取类似@e1、@e2的元素引用) - 交互:使用引用进行点击、填写和选择
- 重新获取快照:导航或 DOM 发生变化后,获取新的引用
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 "[email protected]"
agent-browser fill @e2 "password123"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i # Check result
命令链式调用
可在单次 shell 调用中使用 && 链式执行命令。浏览器会通过后台守护进程在命令之间保持运行,因此链式调用安全且比单独调用更高效。
# 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 "[email protected]" && 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
何时使用链式调用: 如果无需读取中间命令的输出即可继续(例如,打开页面 + 等待 + 截图),请使用 &&。如果需要先解析输出(例如,通过快照发现引用,再使用这些引用进行交互),请分开运行命令。
处理身份验证
自动化操作需要登录的网站时,请选择合适的方法:
选项 1:从用户的浏览器导入身份验证信息(适合一次性任务,速度最快)
# Connect to the user's running Chrome (they're already logged in)
agent-browser --auto-connect state save ./auth.json
# Use that auth state
agent-browser --state ./auth.json open https://app.example.com/dashboard
状态文件以明文形式包含会话令牌——请将其添加到 .gitignore,并在不再需要时删除。设置 AGENT_BROWSER_ENCRYPTION_KEY 可对静态数据进行加密。
选项 2:持久化配置文件(适合重复任务,最简单)
# First run: login manually or via automation
agent-browser --profile ~/.myapp open https://app.example.com/login
# ... fill credentials, submit ...
# All future runs: already authenticated
agent-browser --profile ~/.myapp open https://app.example.com/dashboard
选项 3:会话名称(自动保存/恢复 Cookie 和 localStorage)
agent-browser --session-name myapp open https://app.example.com/login
# ... login flow ...
agent-browser close # State auto-saved
# Next time: state auto-restored
agent-browser --session-name myapp open https://app.example.com/dashboard
选项 4:身份验证保险库(凭据加密存储,通过名称登录)
echo "$PASSWORD" | agent-browser auth save myapp --url https://app.example.com/login --username user --password-stdin
agent-browser auth login myapp
auth login 会使用 load 导航,然后等待登录表单选择器出现,再填写/点击;这在延迟加载的 SPA 登录界面上更可靠。
选项 5:状态文件(手动保存/加载)
# After logging in:
agent-browser state save ./auth.json
# In a future session:
agent-browser state load ./auth.json
agent-browser open https://app.example.com/dashboard
有关 OAuth、2FA、基于 Cookie 的身份验证和令牌刷新模式,请参阅 references/authentication.md。
必备命令
# Navigation
agent-browser open <url> # Navigate (aliases: goto, navigate)
agent-browser close # Close browser
agent-browser close --all # Close all active sessions
# Snapshot
agent-browser snapshot -i # Interactive elements with refs (recommended)
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
agent-browser get cdp-url # Get CDP WebSocket URL
# 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
agent-browser wait --text "Welcome" # Wait for text to appear (substring match)
agent-browser wait --fn "!document.body.innerText.includes('Loading...')" # Wait for text to disappear
agent-browser wait "#spinner" --state hidden # Wait for element to disappear
# 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
# Network
agent-browser network requests # Inspect tracked requests
agent-browser network requests --type xhr,fetch # Filter by resource type
agent-browser network requests --method POST # Filter by HTTP method
agent-browser network requests --status 2xx # Filter by status (200, 2xx, 400-499)
agent-browser network request <requestId> # View full request/response detail
agent-browser network route "**/api/*" --abort # Block matching requests
agent-browser network har start # Start HAR recording
agent-browser network har stop ./capture.har # Stop and save HAR file
# Viewport & Device Emulation
agent-browser set viewport 1920 1080 # Set viewport size (default: 1280x720)
agent-browser set viewport 1920 1080 2 # 2x retina (same CSS size, higher res screenshots)
agent-browser set device "iPhone 14" # Emulate device (viewport + user agent)
# 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 screenshot --screenshot-dir ./shots # Save to custom directory
agent-browser screenshot --screenshot-format jpeg --screenshot-quality 80
agent-browser pdf output.pdf # Save as PDF
# Live preview / streaming
agent-browser stream enable # Start runtime WebSocket streaming on an auto-selected port
agent-browser stream enable --port 9223 # Bind a specific localhost port
agent-browser stream status # Inspect enabled state, port, connection, and screencasting
agent-browser stream disable # Stop runtime streaming and remove the .stream metadata file
# Clipboard
agent-browser clipboard read # Read text from clipboard
agent-browser clipboard write "Hello, World!" # Write text to clipboard
agent-browser clipboard copy # Copy current selection
agent-browser clipboard paste # Paste from clipboard
# Dialogs (alert, confirm, prompt)
agent-browser dialog accept # Accept dialog
agent-browser dialog accept "my input" # Accept prompt dialog with text
agent-browser dialog dismiss # Dismiss/cancel dialog
agent-browser dialog status # Check if a dialog is currently open
# 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
流式传输
每个会话都会自动在操作系统分配的端口上启动 WebSocket 流服务器。使用 agent-browser stream status 查看绑定的端口和连接状态。使用 stream disable 关闭该服务器,使用 stream enable --port <port> 在指定端口上重新启用。
批量执行
将由字符串数组构成的 JSON 数组通过管道传递给 batch,即可在单次调用中执行多条命令。这样可以避免执行多步工作流时每条命令都产生的进程启动开销。
echo '[
["open", "https://example.com"],
["snapshot", "-i"],
["click", "@e1"],
["screenshot", "result.png"]
]' | agent-browser batch --json
# Stop on first error
agent-browser batch --bail < commands.json
如果命令序列已知,且不依赖中间输出,请使用 batch。如果需要在步骤之间解析输出(例如,通过快照发现引用,再进行交互),请使用单独的命令或通过 && 链式调用。
常见模式
提交表单
agent-browser open https://example.com/signup
agent-browser snapshot -i
agent-browser fill @e1 "Jane Doe"
agent-browser fill @e2 "[email protected]"
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
auth login 会在交互前等待用户名、密码和提交按钮的选择器出现,等待超时时间与默认操作超时时间一致。
使用状态持久化进行身份验证
# 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
使用 iframe
iframe 内容会自动内嵌在快照中。iframe 内的引用会携带框架上下文,因此可以直接与其交互。
agent-browser open https://example.com/checkout
agent-browser snapshot -i
# @e1 [heading] "Checkout"
# @e2 [Iframe] "payment-frame"
# @e3 [input] "Card number"
# @e4 [input] "Expiry"
# @e5 [button] "Pay"
# Interact directly — no frame switch needed
agent-browser fill @e3 "4111111111111111"
agent-browser fill @e4 "12/28"
agent-browser click @e5
# To scope a snapshot to one iframe:
agent-browser frame @e2
agent-browser snapshot -i # Only iframe content
agent-browser frame main # Return to main frame
数据提取
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
连接到现有 Chrome
# 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
自动连接会通过 DevToolsActivePort 和常见调试端口(9222、9229)查找 Chrome;如果基于 HTTP 的 CDP 发现失败,则会回退到直接建立 WebSocket 连接。
配色方案(深色模式)
# 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
视口和响应式测试
# Set a custom viewport size (default is 1280x720)
agent-browser set viewport 1920 1080
agent-browser screenshot desktop.png
# Test mobile-width layout
agent-browser set viewport 375 812
agent-browser screenshot mobile.png
# Retina/HiDPI: same CSS layout at 2x pixel density
# Screenshots stay at logical viewport size, but content renders at higher DPI
agent-browser set viewport 1920 1080 2
agent-browser screenshot retina.png
# Device emulation (sets viewport + user agent in one step)
agent-browser set device "iPhone 14"
agent-browser screenshot device.png
scale 参数(第 3 个参数)可设置 window.devicePixelRatio,而不会改变 CSS 布局。在测试视网膜屏幕渲染或截取更高分辨率的屏幕截图时使用。
可视化浏览器(调试)
agent-browser --headed open https://example.com
agent-browser highlight @e1 # Highlight element
agent-browser inspect # Open Chrome DevTools for the active page
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)
使用 AGENT_BROWSER_HEADED=1 通过环境变量启用有头模式。浏览器扩展在有头模式和无头模式下均可使用。
本地文件(PDF、HTML)
# 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
iOS 模拟器(Mobile Safari)
# 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
**要求:**macOS 和 Xcode、Appium(npm install -g appium && appium driver install xcuitest)
**真实设备:**如果已预先配置,也可使用实体 iOS 设备。使用 --device "<UDID>",其中 UDID 来自 xcrun xctrace list devices。
安全
所有安全功能均为可选功能。默认情况下,agent-browser 不会限制导航、操作或输出。
内容边界(建议用于 AI Agent)
启用 --content-boundaries,即可用标记包裹来自页面的输出,帮助大模型区分工具输出与不可信的页面内容:
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> ---
域名允许列表
将导航限制在可信域名内。*.example.com 这类通配符也会匹配裸域名 example.com。对非允许域名的子资源请求、WebSocket 和 EventSource 连接也会被阻止。请添加目标页面所依赖的 CDN 域名:
export AGENT_BROWSER_ALLOWED_DOMAINS="example.com,*.example.com"
agent-browser open https://example.com # OK
agent-browser open https://malicious.com # Blocked
操作策略
使用策略文件限制具有破坏性的操作:
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,验证操作是否达到了预期效果。此命令会将当前无障碍树与本次会话中上次获取的快照进行比较。
# 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)
用于视觉回归测试或监控:
# 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 的输出使用 + 表示新增内容,使用 - 表示移除内容,类似于 git diff。diff screenshot 会生成差异图像,用红色突出显示像素变化,并给出不匹配百分比。
超时和加载缓慢的页面
默认超时时间为 25 秒。可通过 AGENT_BROWSER_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
对于持续加载缓慢的网站,请在 open 后使用 wait --load networkidle,以确保页面完全加载后再获取快照。如果某个特定元素渲染缓慢,可使用 wait <selector> 或 wait @ref 直接等待该元素。
JavaScript 对话框(alert / confirm / prompt)
页面打开 JavaScript 对话框(alert()、confirm() 或 prompt())时,会阻塞所有其他浏览器命令(snapshot、screenshot、click 等),直到对话框关闭。如果命令开始意外超时,请检查是否有待处理的对话框:
# Check if a dialog is blocking
agent-browser dialog status
# Accept the dialog (dismiss the alert / click OK)
agent-browser dialog accept
# Accept a prompt dialog with input text
agent-browser dialog accept "my input"
# Dismiss the dialog (click Cancel)
agent-browser dialog dismiss
存在待处理的对话框时,所有命令响应都会包含一个 warning 字段,指明对话框类型和消息。在 --json 模式下,该字段会作为响应对象中的 "warning" 键出现。
会话管理与清理
同时运行多个 Agent 或自动化任务时,请始终使用命名会话,以避免冲突:
# 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
完成后请始终关闭浏览器会话,以免遗留进程:
agent-browser close # Close default session
agent-browser --session agent1 close # Close specific session
agent-browser close --all # Close all active sessions
如果之前的会话未正确关闭,守护进程可能仍在运行。使用 agent-browser close 清理,或使用 agent-browser close --all 一次性关闭所有会话。
若要在一段时间无操作后自动关闭守护进程(适用于临时环境或 CI 环境):
AGENT_BROWSER_IDLE_TIMEOUT_MS=60000 agent-browser open example.com
Ref 生命周期(重要)
页面发生变化时,Ref(@e1、@e2 等)会失效。以下操作后请务必重新获取快照:
- 点击会导航到其他页面的链接或按钮
- 提交表单
- 动态内容加载(下拉菜单、模态框)
agent-browser click @e5 # Navigates to new page
agent-browser snapshot -i # MUST re-snapshot
agent-browser click @e1 # Use new refs
带标注的截图(视觉模式)
使用 --annotate 拍摄截图,并在交互元素上叠加编号标签。每个标签 [N] 对应 ref @eN。此操作也会缓存 refs,因此你无需单独创建快照即可立即与元素交互。
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
以下情况适合使用带标注的截图:
- 页面上有未标注的图标按钮或纯视觉元素
- 你需要确认视觉布局或样式
- 页面上有画布或图表元素(文本快照中不可见)
- 你需要根据元素位置进行空间推理
语义定位器(Refs 的替代方案)
当 refs 不可用或不可靠时,请使用语义定位器:
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "[email protected]"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click
JavaScript 求值(eval)
使用 eval 在浏览器上下文中运行 JavaScript。Shell 引号可能会破坏复杂表达式——使用 --stdin 或 -b 来避免此问题。
# 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)"
**这很重要的原因:**Shell 处理命令时,内部双引号、! 字符(历史扩展)、反引号和 $() 都可能破坏 JavaScript,导致它无法正确传递给 agent-browser。--stdin 和 -b 标志可完全绕过 Shell 解析。
经验法则:
- 单行且无嵌套引号 -> 使用常规的
eval 'expression'并以单引号括起即可 - 有嵌套引号、箭头函数、模板字面量或多行内容 -> 使用
eval --stdin <<'EVALEOF' - 程序化生成的脚本 -> 使用
eval -b和 base64
配置文件
在项目根目录中创建 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 | Ref 生命周期、失效规则和故障排除 |
| references/session-management.md | 并行会话、状态持久化和并发抓取 |
| references/authentication.md | 登录流程、OAuth、2FA 处理和状态复用 |
| references/video-recording.md | 用于调试和文档编写的录制工作流 |
| references/profiling.md | 用于性能分析的 Chrome DevTools 性能分析 |
| references/proxy-support.md | 代理配置、地理位置测试和轮换代理 |
浏览器引擎选择
使用 --engine 选择本地浏览器引擎。默认值为 chrome。
# Use Lightpanda (fast headless browser, requires separate install)
agent-browser --engine lightpanda open example.com
# Via environment variable
export AGENT_BROWSER_ENGINE=lightpanda
agent-browser open example.com
# With custom binary path
agent-browser --engine lightpanda --executable-path /path/to/lightpanda open example.com
支持的引擎:
chrome(默认)——通过 CDP 使用 Chrome/Chromiumlightpanda——通过 CDP 使用 Lightpanda 无头浏览器(速度快 10 倍,内存占用比 Chrome 少 10 倍)
Lightpanda 不支持 --extension、--profile、--state 或 --allow-file-access。请从 https://lightpanda.io/docs/open-source/installation 安装 Lightpanda。
可观测性仪表板
该仪表板是一个独立的后台服务,可显示所有会话的实时浏览器视口、命令活动和控制台输出。
# Install the dashboard once
agent-browser dashboard install
# Start the dashboard server (background, port 4848)
agent-browser dashboard start
# All sessions are automatically visible in the dashboard
agent-browser open example.com
# Stop the dashboard
agent-browser dashboard stop
仪表板在浏览器会话之外独立运行,端口为 4848(可通过 --port 配置)。所有会话都会自动向仪表板推送数据。
即用模板
| 模板 | 描述 |
|---|---|
| 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