mcpField
B
browser-use

browser-use

github.com/shawnpanaAgent 工作流2130 次安装30 周前更新
代码仓库

关于 browser-use

通过 `browser-use` 命令行操作持久浏览器会话的自动化技能,支持无头浏览器、本地 Chrome 和云端浏览器工作流,也可作为 MCP 服务运行。

主要功能

  1. 01浏览并检查网页
  2. 02按元素索引点击和输入
  3. 03跨命令保持会话
  4. 04连接 Chrome 或云端浏览器
  5. 05作为 MCP 服务运行

适用场景

  1. 01自动执行网站交互
  2. 02使用 Chrome 配置文件访问已登录网站
  3. 03通过隧道检查本地开发服务器
  4. 04在独立会话中运行浏览器流程

MCP 相关

命令行可通过 `--mcp` 作为 MCP 服务运行,向 MCP 客户端提供浏览器自动化功能。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/shawnpana/browser-use --skill browser-use

安装后在 Claude Code 中输入/browser-use确认已加载。

附带文件references/cdp-python.mdreferences/multi-session.md

详细介绍

使用 browser-use CLI 进行浏览器自动化

browser-use 命令可提供快速、持久的浏览器自动化。后台守护进程会让浏览器在多条命令之间保持开启,每次调用的延迟约为 50 ms。

前提条件

browser-use doctor    # Verify installation

有关设置详情,请参阅 https://github.com/browser-use/browser-use/blob/main/browser_use/skill_cli/README.md

核心工作流

  1. 导航:browser-use open <url> — 启动无头浏览器并打开页面
  2. 检查:browser-use state — 返回带有索引的可点击元素
  3. 交互:使用 state 中的索引(browser-use click 5、browser-use input 3 "text")
  4. 验证:使用 browser-use state 或 browser-use screenshot 进行确认
  5. 重复:浏览器会在多条命令之间保持开启

如果命令失败,请先运行 browser-use close 清除故障会话,然后重试。

如需使用用户现有的 Chrome(保留登录状态和 Cookie):先运行 browser-use connect。 如需改用云浏览器:先运行 browser-use cloud connect。 完成任一操作后,命令的用法都相同。

浏览器模式

browser-use open <url>                         # Default: headless Chromium (no setup needed)
browser-use --headed open <url>                # Visible window (for debugging)
browser-use connect                            # Connect to user's Chrome (preserves logins/cookies)
browser-use cloud connect                      # Cloud browser (zero-config, requires API key)
browser-use --profile "Default" open <url>     # Real Chrome with specific profile

运行 connect 或 cloud connect 后,所有后续命令都会发送到该浏览器,无需额外标志。

命令

# 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
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

# Session
browser-use close                         # Close browser and stop daemon
browser-use sessions                      # List active sessions
browser-use close --all                   # Close all sessions

如需高级浏览器控制(CDP、设备模拟、标签页激活),请参阅 references/cdp-python.md。

云 API

browser-use cloud connect                 # Provision cloud browser and connect (zero-config)
browser-use cloud login <api-key>         # Save API key (or set BROWSER_USE_API_KEY)
browser-use cloud logout                  # Remove API key
browser-use cloud v2 GET /browsers        # REST passthrough (v2 or v3)
browser-use cloud v2 POST /tasks '{"task":"...","url":"..."}'
browser-use cloud v2 poll <task-id>       # Poll task until done
browser-use cloud v2 --help               # Show API endpoints

cloud connect 会创建一个带持久配置文件的云浏览器(首次使用时自动创建),通过 CDP 连接并打印一个实时 URL。browser-use close 会断开连接并停止云浏览器。如需自定义浏览器设置(代理、超时、指定配置文件),请直接使用 cloud v2 POST /browsers 并传入所需参数。

Agent 自助注册

仅在你还没有 API 密钥时使用此功能(运行 browser-use doctor 检查是否已设置 api_key)。如果已登录,请完全跳过此步骤。

  1. browser-use cloud signup — 获取挑战
  2. 解答挑战
  3. browser-use cloud signup --verify <challenge-id> <answer> — 验证并保存 API 密钥
  4. browser-use cloud signup --claim — 生成供他人认领账户的 URL

隧道

browser-use tunnel <port>                 # Start Cloudflare 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 profile list                  # List detected browsers and profiles
browser-use profile sync --all            # Sync profiles to cloud
browser-use profile update                # Download/update profile-use binary

命令串联

可以使用 && 串联命令。浏览器通过守护进程保持运行,因此串联命令安全又高效。

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 来查找索引,请分开运行。

常见工作流

已通过身份验证的浏览

如果任务需要访问已登录的网站(Gmail、GitHub、内部工具),请使用 Chrome 配置文件:

browser-use profile list                           # Check available profiles
# Ask the user which profile to use, then:
browser-use --profile "Default" open https://github.com  # Already logged in
暴露本地开发服务器
browser-use tunnel 3000                            # → https://abc.trycloudflare.com
browser-use open https://abc.trycloudflare.com     # Browse the tunnel

多个浏览器

如需运行子 Agent 工作流或并行运行多个浏览器,请使用 --session NAME。每个会话都有自己的浏览器。请参阅 references/multi-session.md。

配置

browser-use config list                            # Show all config values
browser-use config set cloud_connect_proxy jp      # Set a value
browser-use config get cloud_connect_proxy         # Get a value
browser-use config unset cloud_connect_timeout     # Remove a value
browser-use doctor                                 # Shows config + diagnostics
browser-use setup                                  # Interactive post-install setup

配置存储在 ~/.browser-use/config.json 中。

全局选项

选项描述
--headed显示浏览器窗口
--profile [NAME]使用真实的 Chrome(不带参数的 --profile 使用 "Default")
--cdp-url <url>通过 CDP URL(http:// 或 ws://)连接
--session NAME指定会话(默认值:"default")
--json以 JSON 格式输出
--mcp通过 stdin/stdout 作为 MCP 服务运行

提示

  1. 始终先运行 state,查看可用元素及其索引
  2. 调试时使用 --headed,查看浏览器的运行情况
  3. 会话会持续保留 — 浏览器会在多条命令之间保持开启
  4. CLI 别名:bu、browser 和 browseruse 均可使用
  5. 如果命令失败,请先运行 browser-use close,然后重试

故障排查

  • 浏览器无法启动? 运行 browser-use close,然后运行 browser-use --headed open <url>
  • 找不到元素? 运行 browser-use scroll down,然后运行 browser-use state
  • 运行诊断: browser-use doctor

清理

browser-use close                         # Close browser session
browser-use tunnel stop --all             # Stop tunnels (if any)

评论

支持 Markdown