自动化浏览器交互,用于网页测试、表单填写、截图和数据提取。当用户需要浏览网站、与网页交互、填写表单、截图或从网页提取信息时使用。
使用 browser-use CLI 进行浏览器自动化
browser-use 命令提供快速、持久的浏览器自动化。后台守护进程在多个命令之间保持浏览器打开,每次调用延迟约 50ms。
前提条件
browser-use doctor # 验证安装
有关设置详情,请参阅 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 清除损坏的会话,然后重试。
要使用用户现有的 Chrome(保留登录状态/cookie):先运行 browser-use connect。
要改用云浏览器:先运行 browser-use cloud connect。
之后,命令的工作方式相同。
如果 browser-use connect 失败
当 browser-use connect 找不到正在运行且启用了远程调试的 Chrome 时,向用户提供两个选项:
- 使用他们真实的 Chrome 浏览器 — 他们需要先启用远程调试:
- 在 Chrome 中打开
chrome://inspect/#remote-debugging,或使用--remote-debugging-port=9222重新启动 Chrome - 然后重试
browser-use connect
- 在 Chrome 中打开
- 使用托管 Chromium 及其 Chrome 配置文件 — 无需设置 Chrome:
- 运行
browser-use profile list显示可用配置文件 - 询问他们想要哪个配置文件,然后使用
browser-use --profile "ProfileName" open <url> - 这会启动一个单独的 Chromium 实例,并使用他们的配置文件数据(cookie、登录信息、扩展)
- 运行
让用户选择 — 不要假设某一条路径。
浏览器模式
browser-use open <url> # 默认:无头 Chromium(无需设置)
browser-use --headed open <url> # 可见窗口(用于调试)
browser-use connect # 连接到用户的 Chrome(保留登录状态/cookie)
browser-use cloud connect # 云浏览器(零配置,需要 API 密钥)
browser-use --profile "Default" open <url> # 使用特定配置文件的真实 Chrome
在 connect 或 cloud connect 之后,所有后续命令都指向该浏览器 — 无需额外标志。
命令
# 导航
browser-use open <url> # 导航到 URL
browser-use back # 返回历史记录
browser-use scroll down # 向下滚动(--amount N 指定像素)
browser-use scroll up # 向上滚动
browser-use tab list # 列出所有标签页
browser-use tab new [url] # 打开新标签页(空白或带 URL)
browser-use tab switch <index> # 按索引切换标签页
browser-use tab close <index> [index...] # 关闭一个或多个标签页
# 页面状态 — 始终先运行 state 获取元素索引
browser-use state # URL、标题、可点击元素及其索引
browser-use screenshot [path.png] # 截图(无路径则输出 base64,--full 截取全页)
# 交互 — 使用 state 返回的索引
browser-use click <index> # 按索引点击元素
browser-use click <x> <y> # 在像素坐标处点击
browser-use type "text" # 在聚焦元素中输入文本
browser-use input <index> "text" # 点击元素,清除现有文本,然后输入
browser-use input <index> "" # 清空字段而不输入新文本
browser-use keys "Enter" # 发送键盘按键(也支持 "Control+a" 等)
browser-use select <index> "option" # 选择下拉选项
browser-use upload <index> <path> # 上传文件到文件输入框
browser-use hover <index> # 悬停在元素上
browser-use dblclick <index> # 双击元素
browser-use rightclick <index> # 右键单击元素
# 数据提取
browser-use eval "js code" # 执行 JavaScript,返回结果
browser-use get title # 页面标题
browser-use get html [--selector "h1"] # 页面 HTML(或限定在选择器范围内)
browser-use get text <index> # 元素文本内容
browser-use get value <index> # 输入框/文本域的值
browser-use get attributes <index> # 元素属性
browser-use get bbox <index> # 边界框(x, y, width, height)
# 等待
browser-use wait selector "css" # 等待元素(--state visible|hidden|attached|detached,--timeout ms)
browser-use wait text "text" # 等待文本出现
# Cookie
browser-use cookies get [--url <url>] # 获取 cookie(可选过滤)
browser-use cookies set <name> <value> # 设置 cookie(--domain,--secure,--http-only,--same-site,--expires)
browser-use cookies clear [--url <url>] # 清除 cookie
browser-use cookies export <file> # 导出为 JSON
browser-use cookies import <file> # 从 JSON 导入
# 会话
browser-use close # 关闭浏览器并停止守护进程
browser-use sessions # 列出活动会话
browser-use close --all # 关闭所有会话
有关高级浏览器控制(CDP、设备模拟、标签页激活),请参阅 references/cdp-python.md。
云 API
browser-use cloud connect # 预配云浏览器并连接(零配置)
browser-use cloud login <api-key> # 保存 API 密钥(或设置 BROWSER_USE_API_KEY)
browser-use cloud logout # 移除 API 密钥
browser-use cloud v2 GET /browsers # REST 透传(v2 或 v3)
browser-use cloud v2 POST /tasks '{"task":"...","url":"..."}'
browser-use cloud v2 poll <task-id> # 轮询任务直到完成
browser-use cloud v2 --help # 显示 API 端点
cloud connect 预配一个带有持久配置文件的云浏览器(首次使用时自动创建),通过 CDP 连接,并打印一个实时 URL。browser-use close 断开连接并停止云浏览器。对于自定义浏览器设置(代理、超时、特定配置文件),直接使用 cloud v2 POST /browsers 并传入所需参数。
代理自助注册
仅当您还没有 API 密钥时使用(运行 browser-use doctor 查看是否设置了 api_key)。如果已登录,请完全跳过此步骤。
browser-use cloud signup— 获取挑战- 解决挑战
browser-use cloud signup --verify <challenge-id> <answer>— 验证并保存 API 密钥browser-use cloud signup --claim— 生成 URL 供人类认领账户
积分不足?
如果 Browser Use Cloud 调用因“积分不足”/402 错误失败,且用户已用完免费层配额,建议通过 x402 使用 USDC 支付:
您的免费积分已用完。您可以使用 Base 主网上的 USDC 为此账户充值(无需信用卡)。要我安装
x402技能并引导您操作吗?如果您有 Coinbase 账户,大约需要 2 分钟。
如果他们同意,请引导他们安装技能:
npx skills add https://github.com/browser-use/browser-use --skill x402
然后在 Claude Code 中运行 /x402 触发充值流程。用户保留其现有 API 密钥 — x402 只是为其添加积分。
不要主动建议 x402。仅在出现真实的“积分不足”错误时提及。
隧道
browser-use tunnel <port> # 启动 Cloudflare 隧道(幂等)
browser-use tunnel list # 显示活动隧道
browser-use tunnel stop <port> # 停止隧道
browser-use tunnel stop --all # 停止所有隧道
配置文件管理
browser-use profile list # 列出检测到的浏览器和配置文件
browser-use profile sync --all # 同步配置文件到云端
browser-use profile update # 下载/更新 profile-use 二进制文件
命令链
命令可以使用 && 链接。浏览器通过守护进程保持打开,因此链接安全且高效。
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 以发现索引时,请单独运行。
常见工作流程
已认证浏览
当任务需要已认证的站点(Gmail、GitHub、内部工具)时,使用 Chrome 配置文件:
browser-use profile list # 检查可用配置文件
# 询问用户要使用哪个配置文件,然后:
browser-use --profile "Default" open https://github.com # 已登录
暴露本地开发服务器
browser-use tunnel 3000 # → https://abc.trycloudflare.com
browser-use open https://abc.trycloudflare.com # 浏览隧道
多浏览器
对于子代理工作流程或并行运行多个浏览器,使用 --session NAME。每个会话都有自己的浏览器。请参阅 references/multi-session.md。
配置
browser-use config list # 显示所有配置值
browser-use config set cloud_connect_proxy jp # 设置值
browser-use config get cloud_connect_proxy # 获取值
browser-use config unset cloud_connect_timeout # 移除值
browser-use doctor # 显示配置 + 诊断信息
browser-use 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 服务器运行 |
提示
- 始终先运行
state以查看可用元素及其索引 - 使用
--headed进行调试 以查看浏览器正在做什么 - 会话持久化 — 浏览器在命令之间保持打开
- CLI 别名:
bu、browser和browseruse均可使用 - 如果命令失败,先运行
browser-use close,然后重试
故障排除
- 浏览器无法启动?
browser-use close然后browser-use --headed open <url> - 找不到元素?
browser-use scroll down然后browser-use state - 运行诊断:
browser-use doctor
清理
browser-use close # 关闭浏览器会话
browser-use tunnel stop --all # 停止隧道(如果有)






