关于 remote-browser
remote-browser 是一项 Agent 技能,可在云 VM、CI 和编码 Agent 等隔离的远程环境中控制无头浏览器。它通过 `browser-use` 检查和操作页面、管理会话,并可通过隧道访问本地开发服务器。
主要功能
- 01通过 `browser-use` 控制无头浏览器
- 02检查页面及元素索引
- 03导航、点击、输入和截图
- 04通过云模式或 CDP 连接
- 05为本地开发服务器创建隧道
- 06支持多个 Agent 共享浏览器标签页
适用场景
- 01在远程隔离环境中自动执行浏览器任务
- 02测试本地运行的开发服务器
- 03让多个 Agent 共享浏览器
- 04检查并操作网页
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ shawnpana/ browser-use --skill remote-browser安装后在 Claude Code 中输入/remote-browser确认已加载。
详细介绍
沙盒 Agent 的浏览器自动化
此技能适用于运行在沙盒远程机器(云 VM、CI、编码 Agent)上的 Agent,这些 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
命令
# Navigation
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
# Page State — always run state first to get element indices
browser-use state # URL, title, clickable elements with indices
browser-use screenshot [path.png] # Screenshot (base64 if no path, --full for full page)
# Interactions — use indices from 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
# Data Extraction
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)
# Wait
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
# Cookies
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 — persistent session with browser access
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
# Session
browser-use close # Close browser and stop daemon
browser-use sessions # List active sessions
browser-use close --all # Close all sessions
Python browser 对象提供: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)。
隧道
通过 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 "[email protected]" && 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 后仍会保持运行。
多 Agent(--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)