用途
remote-browser 是一项浏览器自动化技能,专为运行在沙箱化远程机器(云虚拟机、CI 环境、编码智能体)上的 agent 设计,用于在没有图形界面的情况下控制无头浏览器。
前置条件
验证安装:
browser-use doctor # Verify installation
设置细节参见 https://github.com/browser-use/browser-use/blob/main/browser_use/skill_cli/README.md
核心工作流
- 导航:
browser-use open <url>— 按需启动无头浏览器 - 检查:
browser-use state— 返回带索引的可点击元素 - 交互:使用 state 中的索引(
browser-use click 5、browser-use input 3 "text") - 验证:
browser-use state或browser-use screenshot确认结果 - 重复:命令之间浏览器保持打开
- 清理:完成后执行
browser-use close
浏览器模式
browser-use open <url> # Default: headless Chromium
browser-use cloud connect # Provision cloud browser and connect
browser-use --connect open <url> # Auto-discover running Chrome via CDP
browser-use --cdp-url ws://localhost:9222/... open <url> # Connect via CDP URL
命令
导航
browser-use open <url> # Navigate to URL
browser-use back # Go back in history
browser-use scroll down # Scroll down (--amount N for pixels)
browser-use scroll up # Scroll up
browser-use tab list # List all tabs with lock status
browser-use tab new [url] # Open a new tab (blank or with URL)
browser-use tab switch <index> # Switch to tab by index
browser-use tab close <index> [index...] # Close one or more tabs
页面状态(始终先运行 state 获取元素索引)
browser-use state # URL, title, clickable elements with indices
browser-use screenshot [path.png] # Screenshot (base64 if no path, --full for full page)
交互(使用 state 中的索引)
browser-use click <index> # Click element by index
browser-use click <x> <y> # Click at pixel coordinates
browser-use type "text" # Type into focused element
browser-use input <index> "text" # Click element, then type
browser-use keys "Enter" # Send keyboard keys (also "Control+a", etc.)
browser-use select <index> "option" # Select dropdown option
browser-use upload <index> <path> # Upload file to file input
browser-use hover <index> # Hover over element
browser-use dblclick <index> # Double-click element
browser-use rightclick <index> # Right-click element
数据提取
browser-use eval "js code" # Execute JavaScript, return result
browser-use get title # Page title
browser-use get html [--selector "h1"] # Page HTML (or scoped to selector)
browser-use get text <index> # Element text content
browser-use get value <index> # Input/textarea value
browser-use get attributes <index> # Element attributes
browser-use get bbox <index> # Bounding box (x, y, width, height)
等待
browser-use wait selector "css" # Wait for element (--state visible|hidden|attached|detached, --timeout ms)
browser-use wait text "text" # Wait for text to appear
Cookie
browser-use cookies get [--url <url>] # Get cookies (optionally filtered)
browser-use cookies set <name> <value> # Set cookie (--domain, --secure, --http-only, --same-site, --expires)
browser-use cookies clear [--url <url>] # Clear cookies
browser-use cookies export <file> # Export to JSON
browser-use cookies import <file> # Import from JSON
Python(可访问浏览器的持久会话)
browser-use python "code" # Execute Python (variables persist across calls)
browser-use python --file script.py # Run file
browser-use python --vars # Show defined variables
browser-use python --reset # Clear namespace
Python 浏览器对象提供:browser.url、browser.title、browser.html、browser.goto(url)、browser.back()、browser.click(index)、browser.type(text)、browser.input(index, text)、browser.keys(keys)、browser.upload(index, path)、browser.screenshot(path)、browser.scroll(direction, amount)、browser.wait(seconds)。
会话
browser-use close # Close browser and stop daemon
browser-use sessions # List active sessions
browser-use close --all # Close all sessions
隧道
通过 Cloudflare 隧道将本地开发服务器暴露给浏览器。
browser-use tunnel <port> # Start tunnel (idempotent)
browser-use tunnel list # Show active tunnels
browser-use tunnel stop <port> # Stop tunnel
browser-use tunnel stop --all # Stop all tunnels
命令链式调用
命令可用 && 链接。浏览器通过守护进程持久存在,因此链式调用安全且高效。
browser-use open https://example.com && browser-use state
browser-use input 5 "user@example.com" && browser-use input 6 "password" && browser-use click 7
不需要中间输出时使用链式调用;需要先解析 state 以发现索引时则分开运行。
常见工作流
暴露本地开发服务器
python -m http.server 3000 & # Start dev server
browser-use tunnel 3000 # → https://abc.trycloudflare.com
browser-use open https://abc.trycloudflare.com # Browse the tunnel
隧道独立于浏览器会话,且在 browser-use close 后仍持续存在。
多智能体(--connect 模式)
多个 agent 可通过 --connect 共享同一浏览器。每个 agent 获得自己的标签页,其他 agent 无法干扰。
设置:注册一次,然后在每条 --connect 命令中传入索引:
INDEX=$(browser-use register) # → prints "1"
browser-use --connect $INDEX open <url> # Navigate in agent's own tab
browser-use --connect $INDEX state # Get state from agent's tab
browser-use --connect $INDEX click <element> # Click in agent's tab
标签页锁定:当某个 agent 修改标签页(点击、输入、导航)时,该标签页即锁定给它。其他 agent 试图修改同一标签页会收到错误。
只读访问:state、screenshot、get 和 wait 命令可在任何标签页上工作,不受锁定限制。
Agent 会话在 5 分钟不活动后过期。再次运行 browser-use register 获取新索引。
全局选项
| 选项 | 说明 |
|---|---|
--headed |
显示浏览器窗口 |
--connect |
通过 CDP 自动发现正在运行的 Chrome |
--cdp-url <url> |
通过 CDP URL 连接(http:// 或 ws://) |
--session NAME |
指定命名会话(默认:"default") |
--json |
以 JSON 格式输出 |
提示
- 始终先运行
state查看可用元素及其索引 - 会话持久 — 浏览器在命令之间保持打开,直到你关闭它
- 隧道独立 — 在
browser-use close后仍持续存在 tunnel是幂等的 — 对同一端口再次调用会返回现有 URL
故障排查
- 浏览器无法启动?先
browser-use close再重试。运行browser-use doctor检查。 - 找不到元素?先
browser-use scroll down,再browser-use state - 隧道不工作?用
which cloudflared检查,用browser-use tunnel list查看活动隧道
清理
browser-use close # Close browser session
browser-use tunnel stop --all # Stop tunnels (if any)