agent-browser
原文:🇺🇸 英文
已翻译
包含 3 个脚本检查通过 / 未检测到疑似敏感代码
面向AI Agent的浏览器自动化CLI工具。当用户需要与网站交互时使用,包括页面导航、表单填写、点击按钮、截图、数据提取、Web应用测试或任何浏览器任务自动化。触发场景包括“打开网站”“填写表单”“点击按钮”“截图”“从页面抓取数据”“测试这个Web应用”“登录网站”“自动化浏览器操作”或任何需要程序化Web交互的任务。
19.8k次下载
查看 GitHub 仓库添加于
SKILL.md 内容
查看翻译对照 →基于agent-browser的浏览器自动化
核心工作流程
所有浏览器自动化都遵循以下模式:
- 导航:
agent-browser open <url> - 快照:(获取元素引用,如
agent-browser snapshot -i、@e1)@e2 - 交互:使用引用进行点击、填写、选择操作
- 重新快照:页面导航或DOM变化后,获取新的引用
bash
agent-browser open https://example.com/form
agent-browser snapshot -i
# 输出:@e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"
agent-browser fill @e1 "user@example.com"
agent-browser fill @e2 "password123"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i # 检查结果核心命令
bash
# 导航
agent-browser open <url> # 导航(别名:goto、navigate)
agent-browser close # 关闭浏览器
# 快照
agent-browser snapshot -i # 带引用的交互式元素(推荐)
agent-browser snapshot -s "#selector" # 限定CSS选择器范围
# 交互(使用快照中的@引用)
agent-browser click @e1 # 点击元素
agent-browser fill @e2 "text" # 清空并输入文本
agent-browser type @e2 "text" # 输入文本不清空原有内容
agent-browser select @e1 "option" # 选择下拉选项
agent-browser check @e1 # 勾选复选框
agent-browser press Enter # 按下按键
agent-browser scroll down 500 # 向下滚动页面500像素
# 获取信息
agent-browser get text @e1 # 获取元素文本
agent-browser get url # 获取当前URL
agent-browser get title # 获取页面标题
# 等待
agent-browser wait @e1 # 等待元素出现
agent-browser wait --load networkidle # 等待网络空闲
agent-browser wait --url "**/page" # 等待URL匹配指定模式
agent-browser wait 2000 # 等待2000毫秒
# 捕获
agent-browser screenshot # 将截图保存到临时目录
agent-browser screenshot --full # 整页截图
agent-browser pdf output.pdf # 保存为PDF常见模式
表单提交
bash
agent-browser open https://example.com/signup
agent-browser snapshot -i
agent-browser fill @e1 "Jane Doe"
agent-browser fill @e2 "jane@example.com"
agent-browser select @e3 "California"
agent-browser check @e4
agent-browser click @e5
agent-browser wait --load networkidle带状态持久化的认证
bash
# 登录一次并保存状态
agent-browser open https://app.example.com/login
agent-browser snapshot -i
agent-browser fill @e1 "$USERNAME"
agent-browser fill @e2 "$PASSWORD"
agent-browser click @e3
agent-browser wait --url "**/dashboard"
agent-browser state save auth.json
# 在后续会话中复用
agent-browser state load auth.json
agent-browser open https://app.example.com/dashboard数据提取
bash
agent-browser open https://example.com/products
agent-browser snapshot -i
agent-browser get text @e5 # 获取指定元素的文本
agent-browser get text body > page.txt # 获取页面所有文本
# 输出JSON格式以便解析
agent-browser snapshot -i --json
agent-browser get text @e1 --json并行会话
bash
agent-browser --session site1 open https://site-a.com
agent-browser --session site2 open https://site-b.com
agent-browser --session site1 snapshot -i
agent-browser --session site2 snapshot -i
agent-browser session list可视化浏览器(调试用)
bash
agent-browser --headed open https://example.com
agent-browser highlight @e1 # 高亮元素
agent-browser record start demo.webm # 录制会话引用生命周期(重要)
引用(、等)会在页面变化时失效。在以下操作后必须重新快照:
@e1@e2- 点击链接或按钮导致页面导航
- 表单提交
- 动态内容加载(下拉菜单、模态框)
bash
agent-browser click @e5 # 导航到新页面
agent-browser snapshot -i # 必须重新快照
agent-browser click @e1 # 使用新的引用语义定位器(引用的替代方案)
当引用不可用或不可靠时,使用语义定位器:
bash
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "user@test.com"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click深度文档
| 参考文档 | 使用场景 |
|---|---|
| references/commands.md | 包含所有选项的完整命令参考 |
| references/snapshot-refs.md | 引用生命周期、失效规则、故障排除 |
| references/session-management.md | 并行会话、状态持久化、并发抓取 |
| references/authentication.md | 登录流程、OAuth、2FA处理、状态复用 |
| references/video-recording.md | 录制工作流用于调试和文档 |
| references/proxy-support.md | 代理配置、地域测试、轮换代理 |
即用型模板
| 模板 | 描述 |
|---|---|
| templates/form-automation.sh | 带验证的表单填写 |
| templates/authenticated-session.sh | 一次登录,复用状态 |
| templates/capture-workflow.sh | 结合截图的内容提取 |
bash
./templates/form-automation.sh https://example.com/form
./templates/authenticated-session.sh https://app.example.com/login
./templates/capture-workflow.sh https://example.com ./output