mcpField
B
browser-use

browser-use

github.com/makerjackieAgent 工作流140 次安装36 周前更新
代码仓库

关于 browser-use

browser-use 是用于浏览器自动化的命令行技能,可在多个命令间保留会话,支持本地 Chrome、Chromium 和云端浏览器,适合需要执行多步骤网页任务的 Agent。

主要功能

  1. 01跨命令保留浏览器会话
  2. 02导航、页面检查与交互
  3. 03执行 JavaScript 和 Python
  4. 04管理标签页、Cookie 与配置文件
  5. 05启动远程浏览器任务与隧道

适用场景

  1. 01自动完成多步骤网页操作
  2. 02使用已有 Chrome 登录状态访问网站
  3. 03通过云端浏览器访问本地开发服务器

安装

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

$npx skills add https://github.com/makerjackie/jackie-skills-starter --skill browser-use

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

详细介绍

使用 browser-use CLI 实现浏览器自动化

browser-use 命令可提供快速、持久的浏览器自动化功能。它会在多条命令之间保持浏览器会话,从而支持复杂的多步骤工作流。

前置条件

使用此技能前,必须安装并配置 browser-use。运行诊断以进行验证:

browser-use doctor

如需了解更多信息,请参阅 https://github.com/browser-use/browser-use/blob/main/browser_use/skill_cli/README.md

核心工作流

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

浏览器模式

browser-use --browser chromium open <url>      # Default: headless Chromium
browser-use --browser chromium --headed open <url>  # Visible Chromium window
browser-use --browser real open <url>          # Real Chrome (no profile = fresh)
browser-use --browser real --profile "Default" open <url>  # Real Chrome with your login sessions
browser-use --browser remote open <url>        # Cloud browser
  • chromium:快速、隔离,默认以无头模式运行
  • real:使用真实的 Chrome 二进制文件。不带 --profile 时,会使用位于 ~/.config/browseruse/profiles/cli/ 的持久但空白的 CLI 配置文件。使用 --profile "ProfileName" 时,会复制你实际的 Chrome 配置文件(Cookie、登录信息、扩展程序)
  • remote:支持代理的云托管浏览器

核心命令

# Navigation
browser-use open <url>                    # Navigate to URL
browser-use back                          # Go back
browser-use scroll down                   # Scroll down (--amount N for pixels)

# Page State (always run state first to get element indices)
browser-use state                         # Get URL, title, clickable elements
browser-use screenshot                    # Take screenshot (base64)
browser-use screenshot path.png           # Save screenshot to file

# Interactions (use indices from state)
browser-use click <index>                 # Click element
browser-use type "text"                   # Type into focused element
browser-use input <index> "text"          # Click element, then type
browser-use keys "Enter"                  # Send keyboard keys
browser-use select <index> "option"       # Select dropdown option

# Data Extraction
browser-use eval "document.title"         # Execute JavaScript
browser-use get text <index>              # Get element text
browser-use get html --selector "h1"      # Get scoped HTML

# Wait
browser-use wait selector "h1"            # Wait for element
browser-use wait text "Success"           # Wait for text

# Session
browser-use sessions                      # List active sessions
browser-use close                         # Close current session
browser-use close --all                   # Close all sessions

# AI Agent
browser-use -b remote run "task"          # Run agent in cloud (async by default)
browser-use task status <id>              # Check cloud task progress

命令

导航和标签页
browser-use open <url>                    # Navigate to URL
browser-use back                          # Go back in history
browser-use scroll down                   # Scroll down
browser-use scroll up                     # Scroll up
browser-use scroll down --amount 1000     # Scroll by specific pixels (default: 500)
browser-use switch <tab>                  # Switch to tab by index
browser-use close-tab                     # Close current tab
browser-use close-tab <tab>              # Close specific tab
页面状态
browser-use state                         # Get URL, title, and clickable elements
browser-use screenshot                    # Take screenshot (outputs base64)
browser-use screenshot path.png           # Save screenshot to file
browser-use screenshot --full path.png    # Full page screenshot
交互
browser-use click <index>                 # Click element
browser-use type "text"                   # Type text into focused element
browser-use input <index> "text"          # Click element, then type text
browser-use keys "Enter"                  # Send keyboard keys
browser-use keys "Control+a"              # Send key combination
browser-use select <index> "option"       # Select dropdown option
browser-use hover <index>                 # Hover over element (triggers CSS :hover)
browser-use dblclick <index>              # Double-click element
browser-use rightclick <index>            # Right-click element (context menu)

使用 browser-use state 中的索引。

JavaScript 和数据
browser-use eval "document.title"         # Execute JavaScript, return result
browser-use get title                     # Get page title
browser-use get html                      # Get full page HTML
browser-use get html --selector "h1"      # Get HTML of specific element
browser-use get text <index>              # Get text content of element
browser-use get value <index>             # Get value of input/textarea
browser-use get attributes <index>        # Get all attributes of element
browser-use get bbox <index>              # Get bounding box (x, y, width, height)
Cookie
browser-use cookies get                   # Get all cookies
browser-use cookies get --url <url>       # Get cookies for specific URL
browser-use cookies set <name> <value>    # Set a cookie
browser-use cookies set name val --domain .example.com --secure --http-only
browser-use cookies set name val --same-site Strict  # SameSite: Strict, Lax, or None
browser-use cookies set name val --expires 1735689600  # Expiration timestamp
browser-use cookies clear                 # Clear all cookies
browser-use cookies clear --url <url>     # Clear cookies for specific URL
browser-use cookies export <file>         # Export all cookies to JSON file
browser-use cookies export <file> --url <url>  # Export cookies for specific URL
browser-use cookies import <file>         # Import cookies from JSON file
等待条件
browser-use wait selector "h1"            # Wait for element to be visible
browser-use wait selector ".loading" --state hidden  # Wait for element to disappear
browser-use wait selector "#btn" --state attached    # Wait for element in DOM
browser-use wait text "Success"           # Wait for text to appear
browser-use wait selector "h1" --timeout 5000  # Custom timeout in ms
Python 执行
browser-use python "x = 42"               # Set variable
browser-use python "print(x)"             # Access variable (outputs: 42)
browser-use python "print(browser.url)"   # Access browser object
browser-use python --vars                 # Show defined variables
browser-use python --reset                # Clear Python namespace
browser-use python --file script.py       # Execute Python file

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.screenshot(path)、browser.scroll(direction, amount) — 视觉操作
  • browser.wait(seconds)、browser.extract(query) — 实用工具
Agent 任务
远程模式选项

使用 --browser remote 时,还可使用以下选项:

# Specify LLM model
browser-use -b remote run "task" --llm gpt-4o
browser-use -b remote run "task" --llm claude-sonnet-4-20250514

# Proxy configuration (default: us)
browser-use -b remote run "task" --proxy-country uk

# Session reuse
browser-use -b remote run "task 1" --keep-alive        # Keep session alive after task
browser-use -b remote run "task 2" --session-id abc-123 # Reuse existing session

# Execution modes
browser-use -b remote run "task" --flash       # Fast execution mode
browser-use -b remote run "task" --wait        # Wait for completion (default: async)

# Advanced options
browser-use -b remote run "task" --thinking    # Extended reasoning mode
browser-use -b remote run "task" --no-vision   # Disable vision (enabled by default)

# Using a cloud profile (create session first, then run with --session-id)
browser-use session create --profile <cloud-profile-id> --keep-alive
# → returns session_id
browser-use -b remote run "task" --session-id <session-id>

# Task configuration
browser-use -b remote run "task" --start-url https://example.com  # Start from specific URL
browser-use -b remote run "task" --allowed-domain example.com     # Restrict navigation (repeatable)
browser-use -b remote run "task" --metadata key=value             # Task metadata (repeatable)
browser-use -b remote run "task" --skill-id skill-123             # Enable skills (repeatable)
browser-use -b remote run "task" --secret key=value               # Secret metadata (repeatable)

# Structured output and evaluation
browser-use -b remote run "task" --structured-output '{"type":"object"}'  # JSON schema for output
browser-use -b remote run "task" --judge                 # Enable judge mode
browser-use -b remote run "task" --judge-ground-truth "expected answer"
任务管理
browser-use task list                     # List recent tasks
browser-use task list --limit 20          # Show more tasks
browser-use task list --status finished   # Filter by status (finished, stopped)
browser-use task list --session <id>      # Filter by session ID
browser-use task list --json              # JSON output

browser-use task status <task-id>         # Get task status (latest step only)
browser-use task status <task-id> -c      # All steps with reasoning
browser-use task status <task-id> -v      # All steps with URLs + actions
browser-use task status <task-id> --last 5  # Last N steps only
browser-use task status <task-id> --step 3  # Specific step number
browser-use task status <task-id> --reverse # Newest first

browser-use task stop <task-id>           # Stop a running task
browser-use task logs <task-id>           # Get task execution logs
云会话管理
browser-use session list                  # List cloud sessions
browser-use session list --limit 20       # Show more sessions
browser-use session list --status active  # Filter by status
browser-use session list --json           # JSON output

browser-use session get <session-id>      # Get session details + live URL
browser-use session get <session-id> --json

browser-use session stop <session-id>     # Stop a session
browser-use session stop --all            # Stop all active sessions

browser-use session create                          # Create with defaults
browser-use session create --profile <id>           # With cloud profile
browser-use session create --proxy-country uk       # With geographic proxy
browser-use session create --start-url https://example.com
browser-use session create --screen-size 1920x1080
browser-use session create --keep-alive
browser-use session create --persist-memory

browser-use session share <session-id>              # Create public share URL
browser-use session share <session-id> --delete     # Delete public share
隧道
browser-use tunnel <port>           # Start tunnel (returns URL)
browser-use tunnel <port>           # Idempotent - returns existing URL
browser-use tunnel list             # Show active tunnels
browser-use tunnel stop <port>      # Stop tunnel
browser-use tunnel stop --all       # Stop all tunnels
会话管理
browser-use sessions                      # List active sessions
browser-use close                         # Close current session
browser-use close --all                   # Close all sessions
配置文件管理
本地 Chrome 配置文件(--browser real)
browser-use -b real profile list          # List local Chrome profiles
browser-use -b real profile cookies "Default"  # Show cookie domains in profile
云配置文件(--browser remote)
browser-use -b remote profile list            # List cloud profiles
browser-use -b remote profile list --page 2 --page-size 50
browser-use -b remote profile get <id>        # Get profile details
browser-use -b remote profile create          # Create new cloud profile
browser-use -b remote profile create --name "My Profile"
browser-use -b remote profile update <id> --name "New"
browser-use -b remote profile delete <id>
同步
browser-use profile sync --from "Default" --domain github.com  # Domain-specific
browser-use profile sync --from "Default"                      # Full profile
browser-use profile sync --from "Default" --name "Custom Name" # With custom name
服务控制
browser-use server logs                   # View server logs

常见工作流

暴露本地开发服务

当你有本地开发服务,需要云浏览器访问它时使用。

核心工作流: 启动开发服务 → 创建隧道 → 通过隧道 URL 远程浏览。

# 1. Start your dev server
npm run dev &  # localhost:3000

# 2. Expose it via Cloudflare tunnel
browser-use tunnel 3000
# → url: https://abc.trycloudflare.com

# 3. Now the cloud browser can reach your local server
browser-use --browser remote open https://abc.trycloudflare.com
browser-use state
browser-use screenshot

注意: 隧道独立于浏览器会话。即使执行 browser-use close,隧道也会持续运行,且可单独管理。必须安装 Cloudflared — 运行 browser-use doctor 进行检查。

使用配置文件进行已认证浏览

当任务需要浏览用户已登录的网站(例如 Gmail、GitHub、内部工具)时使用。

核心工作流: 检查现有配置文件 → 询问用户要使用的配置文件和浏览器模式 → 使用该配置文件浏览。仅当不存在合适的配置文件时才同步 Cookie。

在浏览已认证的网站前,Agent 必须:

  1. 询问用户使用 real(本地 Chrome)还是 remote(云端)浏览器
  2. 列出该模式下可用的配置文件
  3. 询问要使用哪个配置文件
  4. 如果没有配置文件包含所需的 Cookie,则提供同步选项(见下文)
第 1 步:检查现有配置文件
# Option A: Local Chrome profiles (--browser real)
browser-use -b real profile list
# → Default: Person 1 ([email protected])
# → Profile 1: Work ([email protected])

# Option B: Cloud profiles (--browser remote)
browser-use -b remote profile list
# → abc-123: "Chrome - Default (github.com)"
# → def-456: "Work profile"
第 2 步:使用所选配置文件浏览
# Real browser — uses local Chrome with existing login sessions
browser-use --browser real --profile "Default" open https://github.com

# Cloud browser — uses cloud profile with synced cookies
browser-use --browser remote --profile abc-123 open https://github.com

用户已通过身份验证 — 无需登录。

注意: 云配置文件中的 Cookie 可能会随时间过期。如果身份验证失败,请从本地 Chrome 配置文件重新同步 Cookie。

步骤 3:同步 Cookie(仅在需要时)

如果用户想使用云浏览器,但没有云端配置文件拥有所需的 Cookie,请从本地 Chrome 配置文件同步。

同步前,Agent 必须:

  1. 询问要使用哪个本地 Chrome 配置文件
  2. 询问要同步哪些域名 — 不要默认同步整个配置文件
  3. 继续操作前先确认

检查本地配置文件中的 Cookie:

browser-use -b real profile cookies "Default"
# → youtube.com: 23
# → google.com: 18
# → github.com: 2

按域名同步(推荐):

browser-use profile sync --from "Default" --domain github.com
# Creates new cloud profile: "Chrome - Default (github.com)"
# Only syncs github.com cookies

同步整个配置文件(谨慎使用):

browser-use profile sync --from "Default"
# Syncs ALL cookies — includes sensitive data, tracking cookies, every session token

仅在用户明确需要整个浏览器状态时使用。

精细控制(高级):

# Export cookies to file, manually edit, then import
browser-use --browser real --profile "Default" cookies export /tmp/cookies.json
browser-use --browser remote --profile <id> cookies import /tmp/cookies.json

使用已同步的配置文件:

browser-use --browser remote --profile <id> open https://github.com
运行子 Agent

使用云端会话并行运行自主浏览器 Agent。

核心工作流: 使用 run 启动任务 → 使用 task status 轮询 → 收集结果 → 清理会话。

  • 会话 = Agent:每个云端会话都是一个拥有独立状态的浏览器 Agent
  • 任务 = 工作:分配给 Agent 的工作;一个 Agent 可以按顺序运行多个任务
  • 会话生命周期:会话停止后无法恢复 — 请启动一个新会话
启动任务
# Single task (async by default — returns immediately)
browser-use -b remote run "Search for AI news and summarize top 3 articles"
# → task_id: task-abc, session_id: sess-123

# Parallel tasks — each gets its own session
browser-use -b remote run "Research competitor A pricing"
# → task_id: task-1, session_id: sess-a
browser-use -b remote run "Research competitor B pricing"
# → task_id: task-2, session_id: sess-b
browser-use -b remote run "Research competitor C pricing"
# → task_id: task-3, session_id: sess-c

# Sequential tasks in same session (reuses cookies, login state, etc.)
browser-use -b remote run "Log into example.com" --keep-alive
# → task_id: task-1, session_id: sess-123
browser-use task status task-1  # Wait for completion
browser-use -b remote run "Export settings" --session-id sess-123
# → task_id: task-2, session_id: sess-123 (same session)
管理与停止
browser-use task list --status finished      # See completed tasks
browser-use task stop task-abc               # Stop a task (session may continue if --keep-alive)
browser-use session stop sess-123            # Stop an entire session (terminates its tasks)
browser-use session stop --all               # Stop all sessions
监控

任务状态专为节省 Token 而设计。 默认输出精简 — 仅在需要时展开:

模式标志Token 数使用场景
默认(无)少轮询进度
紧凑-c中需要完整推理过程时
详细-v多调试操作时
# For long tasks (50+ steps)
browser-use task status <id> -c --last 5   # Last 5 steps only
browser-use task status <id> -v --step 10  # Inspect specific step

实时视图:browser-use session get <session-id> 会返回可用于查看 Agent 的实时 URL。

检测卡住的任务:如果 task status 中的费用/时长不再增加,说明任务卡住了 — 停止该任务并启动一个新的 Agent。

日志:browser-use task logs <task-id> — 仅在任务完成后可用。

全局选项

选项描述
--session NAME使用命名会话(默认:"default")
--browser MODE浏览器模式:chromium、real、remote
--headed显示浏览器窗口(chromium 模式)
--profile NAME浏览器配置文件(本地名称或云端 ID)。适用于 open、session create 等命令 — 不适用于 run(请改用 --session-id)
--json以 JSON 格式输出
--mcp通过 stdin/stdout 作为 MCP 服务运行

会话行为:所有未指定 --session 的命令都会使用同一个 "default" 会话。浏览器会保持打开状态,并在各命令之间复用。使用 --session NAME 并行运行多个浏览器。

提示

  1. 始终先运行 browser-use state,查看可用元素及其索引
  2. 调试时使用 --headed,查看浏览器正在执行的操作
  3. 会话会持续保留 — 浏览器会在命令之间保持打开状态
  4. 使用 --json 进行程序化解析
  5. 同一会话内的 browser-use python 命令会保留 Python 变量
  6. CLI 别名:bu、browser 和 browseruse 的功能均与 browser-use 相同

故障排除

先运行诊断:

browser-use doctor

浏览器无法启动?

browser-use close --all               # Close all sessions
browser-use --headed open <url>       # Try with visible window

找不到元素?

browser-use state                     # Check current elements
browser-use scroll down               # Element might be below fold
browser-use state                     # Check again

会话问题?

browser-use sessions                  # Check active sessions
browser-use close --all               # Clean slate
browser-use open <url>                # Fresh start

task stop 后无法复用会话: 如果停止任务后尝试复用其会话,新任务可能会卡在 "created" 状态。请改为创建新会话:

browser-use session create --profile <profile-id> --keep-alive
browser-use -b remote run "new task" --session-id <new-session-id>

任务卡在 "started" 状态:使用 task status 检查费用 — 如果没有增加,说明任务卡住了。使用 session get 查看实时 URL,然后停止任务并启动新的 Agent。

任务完成后会话仍会保留:任务完成不会自动停止会话。运行 browser-use session stop --all 进行清理。

清理

完成后务必关闭浏览器:

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

评论

支持 Markdown