Vercel Agent Browser Skill
Vercel Agent Browser Skill
Skill by
ara.so — AI Agent Skills collection.
由
ara.so开发的Skill——AI Agent技能合集。
is a fast native Rust CLI for browser automation designed specifically for AI agents. It provides an accessibility-first approach with semantic selectors and ref-based element targeting, making it ideal for LLM-driven web automation.
Key Features:
- Native Rust performance with npm/Homebrew distribution
- Accessibility tree snapshots with stable element refs (, , etc.)
- Semantic locators (role, text, label, placeholder)
- AI chat mode for natural language control
- Batch command execution
- Network interception and HAR recording
- Chrome DevTools Protocol (CDP) streaming
是一款专为AI Agent设计的快速原生Rust CLI浏览器自动化工具。它采用无障碍优先的方法,提供语义选择器和基于引用的元素定位,非常适合LLM驱动的Web自动化。
核心特性:
- 原生Rust性能,支持npm/Homebrew分发
- 带有稳定元素引用(、等)的无障碍树快照
- 语义定位符(角色、文本、标签、占位符)
- 自然语言控制的AI聊天模式
- 批量命令执行
- 网络拦截与HAR录制
- Chrome DevTools Protocol (CDP) 流处理
Global (Recommended)
全局安装(推荐)
bash
npm install -g agent-browser
agent-browser install # Downloads Chrome for Testing
bash
npm install -g agent-browser
agent-browser install # 下载Chrome for Testing
bash
npm install agent-browser
npx agent-browser install
bash
npm install agent-browser
npx agent-browser install
Alternative Methods
其他安装方式
Homebrew (macOS)
Homebrew(macOS)
brew install agent-browser
agent-browser install
brew install agent-browser
agent-browser install
cargo install agent-browser
agent-browser install
cargo install agent-browser
agent-browser install
Linux with system dependencies
带系统依赖的Linux安装
agent-browser install --with-deps
agent-browser install --with-deps
bash
agent-browser upgrade # Auto-detects installation method
bash
agent-browser upgrade # 自动检测安装方式
Element References (@refs)
元素引用(@refs)
The most powerful feature for AI agents is the accessibility snapshot with stable refs:
对AI Agent而言最强大的功能是带有稳定引用的无障碍快照:
Get accessibility tree with element refs
获取带元素引用的无障碍树
Output includes refs like:
输出包含如下引用:
@e1 heading "Example Domain"
@e1 heading "Example Domain"
@e2 link "More information..."
@e2 link "More information..."
@e3 textbox "Search" (placeholder)
@e3 textbox "Search" (placeholder)
Use refs directly in commands
直接在命令中使用引用
agent-browser click @e2
agent-browser fill @e3 "search query"
agent-browser get text @e1
agent-browser click @e2
agent-browser fill @e3 "search query"
agent-browser get text @e1
Traditional Selectors
传统选择器
Standard CSS selectors also work:
bash
agent-browser click "#submit-button"
agent-browser fill "input[name='email']" "user@example.com"
agent-browser get text ".header h1"
标准CSS选择器同样适用:
bash
agent-browser click "#submit-button"
agent-browser fill "input[name='email']" "user@example.com"
agent-browser get text ".header h1"
Find elements by their semantic meaning:
agent-browser find role button click --name "Submit"
agent-browser find role textbox fill "user@example.com" --name "Email"
agent-browser find role button click --name "Submit"
agent-browser find role textbox fill "user@example.com" --name "Email"
agent-browser find text "Sign In" click
agent-browser find text "Welcome" click --exact
agent-browser find text "Sign In" click
agent-browser find text "Welcome" click --exact
agent-browser find label "Password" fill "secret123"
agent-browser find label "Password" fill "secret123"
agent-browser find placeholder "Search..." type "rust cli"
agent-browser find placeholder "Search..." type "rust cli"
agent-browser find testid "login-form" click
agent-browser find testid "login-form" click
Basic Navigation and Interaction
基础导航与交互
Start browser and navigate
启动浏览器并导航
Fill login form using refs from snapshot
使用快照中的引用填写登录表单
agent-browser fill @e5 "username"
agent-browser fill @e6 "password"
agent-browser click @e7
agent-browser fill @e5 "username"
agent-browser fill @e6 "password"
agent-browser click @e7
Or use semantic locators
或者使用语义定位符
agent-browser find label "Username" fill "username"
agent-browser find label "Password" fill "password"
agent-browser find role button click --name "Sign in"
agent-browser find label "Username" fill "username"
agent-browser find label "Password" fill "password"
agent-browser find role button click --name "Sign in"
Wait for navigation
等待导航完成
agent-browser wait --url "**/dashboard"
agent-browser wait --url "**/dashboard"
agent-browser screenshot success.png
agent-browser screenshot success.png
bash
agent-browser open https://forms.example.com
bash
agent-browser open https://forms.example.com
agent-browser fill "#name" "John Doe"
agent-browser fill "#email" "john@example.com"
agent-browser fill "#name" "John Doe"
agent-browser fill "#email" "john@example.com"
agent-browser select "#country" "United States"
agent-browser select "#country" "United States"
agent-browser check "#newsletter"
agent-browser check "#terms"
agent-browser check "#newsletter"
agent-browser check "#terms"
agent-browser upload "#resume" "/path/to/resume.pdf"
agent-browser upload "#resume" "/path/to/resume.pdf"
agent-browser find role button click --name "Submit"
agent-browser find role button click --name "Submit"
Wait for success message
等待成功提示
agent-browser wait --text "Thank you"
agent-browser wait --text "Thank you"
bash
agent-browser open https://news.ycombinator.com
bash
agent-browser open https://news.ycombinator.com
Get page snapshot for structure
获取页面快照查看结构
agent-browser snapshot -i # Interactive mode shows full tree
agent-browser snapshot -i # 交互模式显示完整树结构
Extract specific content
提取特定内容
agent-browser get text ".titleline > a"
agent-browser get text ".titleline > a"
Get multiple elements with JavaScript
使用JavaScript获取多个元素
agent-browser eval "Array.from(document.querySelectorAll('.titleline > a')).map(a => a.textContent)"
agent-browser eval "Array.from(document.querySelectorAll('.titleline > a')).map(a => a.textContent)"
Get structured data as JSON
获取结构化JSON数据
agent-browser eval "JSON.stringify({
title: document.querySelector('title').textContent,
links: Array.from(document.querySelectorAll('.titleline > a')).map(a => ({
text: a.textContent,
url: a.href
}))
})"
agent-browser eval "JSON.stringify({
title: document.querySelector('title').textContent,
links: Array.from(document.querySelectorAll('.titleline > a')).map(a => ({
text: a.textContent,
url: a.href
}))
})"
Reduce overhead by running multiple commands in one invocation:
agent-browser batch
"open
https://example.com"
"snapshot -i"
"click @e2"
"wait 1000"
"screenshot result.png"
agent-browser batch
"open
https://example.com"
"snapshot -i"
"click @e2"
"wait 1000"
"screenshot result.png"
With --bail to stop on first error
使用--bail参数在首次出错时停止
agent-browser batch --bail
"open
https://login.example.com"
"fill #username
user@example.com"
"fill #password ${PASSWORD}"
"click #submit"
"wait --url '**/dashboard'"
agent-browser batch --bail
"open
https://login.example.com"
"fill #username
user@example.com"
"fill #password ${PASSWORD}"
"click #submit"
"wait --url '**/dashboard'"
JSON mode (piped from script)
JSON模式(从脚本管道输入)
echo '[
["open", "
https://example.com"],
["snapshot"],
["click", "@e1"],
["screenshot"]
]' | agent-browser batch --json
echo '[
["open", "
https://example.com"],
["snapshot"],
["click", "@e1"],
["screenshot"]
]' | agent-browser batch --json
Natural language browser control:
agent-browser chat "go to github.com and search for rust browser automation"
agent-browser chat "go to github.com and search for rust browser automation"
> navigate to example.com
> navigate to example.com
> click the first link
> click the first link
> take a screenshot
> take a screenshot
Block specific resources
拦截特定资源
Block resource types
拦截资源类型
agent-browser network route '' --abort --resource-type script
agent-browser network route '' --abort --resource-type image,media
agent-browser network route '' --abort --resource-type script
agent-browser network route '' --abort --resource-type image,media
Mock API responses
模拟API响应
View network requests
查看网络请求
agent-browser network requests
agent-browser network requests --filter api
agent-browser network requests --type fetch,xhr
agent-browser network requests --method POST
agent-browser network requests --status 200
agent-browser network requests
agent-browser network requests --filter api
agent-browser network requests --type fetch,xhr
agent-browser network requests --method POST
agent-browser network requests --status 200
View specific request detail
查看特定请求详情
agent-browser network request req_123abc
agent-browser network request req_123abc
agent-browser network har start
agent-browser network har start
... perform actions ...
... 执行操作 ...
agent-browser network har stop capture.har
agent-browser network har stop capture.har
Screenshot Strategies
截图策略
Basic screenshot (saves to temp if no path)
基础截图(无路径则保存到临时目录)
Save to specific path
保存到指定路径
agent-browser screenshot ./screenshots/page.png
agent-browser screenshot ./screenshots/page.png
agent-browser screenshot --full full-page.png
agent-browser screenshot --full full-page.png
Annotated with element labels
带元素标注的截图
agent-browser screenshot --annotate labeled.png
agent-browser screenshot --annotate labeled.png
Custom directory and format
自定义目录与格式
agent-browser screenshot --screenshot-dir ./shots --screenshot-format jpeg --screenshot-quality 80
agent-browser screenshot --screenshot-dir ./shots --screenshot-format jpeg --screenshot-quality 80
agent-browser eval "document.querySelector('#main').screenshot()" -b > element.png
agent-browser eval "document.querySelector('#main').screenshot()" -b > element.png
Multi-Tab Operations
多标签页操作
Open new tab with label
打开带标签的新标签页
Open link in new tab
在新标签页打开链接
agent-browser click "#external-link" --new-tab
agent-browser click "#external-link" --new-tab
Switch to tab by label
通过标签切换标签页
Switch to tab by ID
通过ID切换标签页
agent-browser tab close docs
agent-browser tab close t2
agent-browser tab close docs
agent-browser tab close t2
Wait for element to appear
等待元素出现
agent-browser wait "#result"
agent-browser wait "#result"
Wait for time (milliseconds)
等待指定时长(毫秒)
Wait for text (substring match)
等待文本出现(子串匹配)
agent-browser wait --text "Success"
agent-browser wait --text "Success"
Wait for URL pattern
等待URL匹配模式
agent-browser wait --url "**/dashboard"
agent-browser wait --url "**/dashboard"
Wait for network idle
等待网络空闲
agent-browser wait --load networkidle
agent-browser wait --load networkidle
Wait for JavaScript condition
等待JavaScript条件满足
agent-browser wait --fn "document.readyState === 'complete'"
agent-browser wait --fn "window.dataLoaded === true"
agent-browser wait --fn "document.readyState === 'complete'"
agent-browser wait --fn "window.dataLoaded === true"
Wait for element to disappear
等待元素消失
agent-browser wait --fn "!document.body.innerText.includes('Loading...')"
agent-browser wait "#spinner" --state hidden
agent-browser wait --fn "!document.body.innerText.includes('Loading...')"
agent-browser wait "#spinner" --state hidden
Keyboard and Mouse Control
键盘与鼠标控制
agent-browser press "Control+a"
agent-browser press "Control+c"
agent-browser press "Enter"
agent-browser press "Tab"
agent-browser press "Control+a"
agent-browser press "Control+c"
agent-browser press "Enter"
agent-browser press "Tab"
Type with real keystrokes (at current focus)
模拟真实按键输入(当前焦点处)
agent-browser keyboard type "Hello World"
agent-browser keyboard type "Hello World"
Insert text without key events
直接插入文本(无按键事件)
agent-browser keyboard inserttext "Pasted content"
agent-browser keyboard inserttext "Pasted content"
Hold and release keys
按住并释放按键
agent-browser keydown "Shift"
agent-browser press "a"
agent-browser keyup "Shift"
agent-browser keydown "Shift"
agent-browser press "a"
agent-browser keyup "Shift"
agent-browser mouse move 100 200
agent-browser mouse down left
agent-browser mouse up left
agent-browser mouse wheel 100 0 # dy dx
agent-browser mouse move 100 200
agent-browser mouse down left
agent-browser mouse up left
agent-browser mouse wheel 100 0 # dy dx
agent-browser drag "#source" "#target"
agent-browser drag "#source" "#target"
Cookies and Storage
Cookie与存储
agent-browser cookies
agent-browser cookies set "sessionId" "abc123"
agent-browser cookies clear
agent-browser cookies
agent-browser cookies set "sessionId" "abc123"
agent-browser cookies clear
Import from cURL
从cURL导入Cookie
agent-browser cookies set --curl curl-cookies.txt
agent-browser cookies set --curl curl-cookies.txt
LocalStorage
LocalStorage管理
agent-browser storage local
agent-browser storage local get "token"
agent-browser storage local set "token" "eyJ..."
agent-browser storage local clear
agent-browser storage local
agent-browser storage local get "token"
agent-browser storage local set "token" "eyJ..."
agent-browser storage local clear
SessionStorage
SessionStorage管理
agent-browser storage session
agent-browser storage session set "tempData" '{"key":"value"}'
agent-browser storage session
agent-browser storage session set "tempData" '{"key":"value"}'
Browser Configuration
浏览器配置
agent-browser set viewport 1920 1080
agent-browser set viewport 1920 1080 2 # Retina (2x scale)
agent-browser set viewport 1920 1080
agent-browser set viewport 1920 1080 2 # 视网膜屏(2倍缩放)
agent-browser set device "iPhone 14"
agent-browser set device "iPhone 14"
agent-browser set geo 37.7749 -122.4194 # San Francisco
agent-browser set geo 37.7749 -122.4194 # 旧金山
agent-browser set offline on
agent-browser set offline off
agent-browser set offline on
agent-browser set offline off
agent-browser set headers '{"X-Custom-Header":"value"}'
agent-browser set headers '{"X-Custom-Header":"value"}'
agent-browser set credentials username password
agent-browser set credentials username password
agent-browser set media dark
agent-browser set media light
agent-browser set media dark
agent-browser set media light
Advanced JavaScript Evaluation
高级JavaScript评估
agent-browser eval "document.title"
agent-browser eval "document.title"
agent-browser eval "
JSON.stringify({
url: window.location.href,
links: Array.from(document.querySelectorAll('a')).map(a => ({
text: a.textContent.trim(),
href: a.href
})).filter(l => l.text)
})
"
agent-browser eval "
JSON.stringify({
url: window.location.href,
links: Array.from(document.querySelectorAll('a')).map(a => ({
text: a.textContent.trim(),
href: a.href
})).filter(l => l.text)
})
"
Binary output (base64)
二进制输出(base64)
agent-browser eval "document.querySelector('canvas').toDataURL()" -b > canvas.png
agent-browser eval "document.querySelector('canvas').toDataURL()" -b > canvas.png
echo "document.body.innerHTML" | agent-browser eval --stdin
echo "document.body.innerHTML" | agent-browser eval --stdin
Automation Script Example
自动化脚本示例
Create a reusable automation script:
login-and-extract.sh
login-and-extract.sh
set -e
SESSION_FILE=".browser-session"
set -e
SESSION_FILE=".browser-session"
agent-browser find label "Email" fill "${USER_EMAIL}"
agent-browser find label "Password" fill "${USER_PASSWORD}"
agent-browser find role button click --name "Sign in"
agent-browser find label "Email" fill "${USER_EMAIL}"
agent-browser find label "Password" fill "${USER_PASSWORD}"
agent-browser find role button click --name "Sign in"
Wait for dashboard
等待仪表盘加载
agent-browser wait --url "**/dashboard"
agent-browser wait 1000
agent-browser wait --url "**/dashboard"
agent-browser wait 1000
DATA=$(agent-browser eval "
JSON.stringify({
user: document.querySelector('.user-name').textContent,
notifications: Array.from(document.querySelectorAll('.notification')).map(n => n.textContent)
})
")
echo "$DATA" | jq .
DATA=$(agent-browser eval "
JSON.stringify({
user: document.querySelector('.user-name').textContent,
notifications: Array.from(document.querySelectorAll('.notification')).map(n => n.textContent)
})
")
echo "$DATA" | jq .
agent-browser screenshot dashboard.png
agent-browser screenshot dashboard.png
agent-browser close
Usage:
```bash
export USER_EMAIL="user@example.com"
export USER_PASSWORD="secret"
chmod +x login-and-extract.sh
./login-and-extract.sh
agent-browser close
使用方式:
```bash
export USER_EMAIL="user@example.com"
export USER_PASSWORD="secret"
chmod +x login-and-extract.sh
./login-and-extract.sh
Batch Automation Pattern
批量自动化模式
For complex multi-step workflows, use batch mode with a script:
javascript
#!/usr/bin/env node
// automation.js
const commands = [
["open", "https://example.com"],
["snapshot"],
// Process snapshot, determine next steps...
["click", "@e5"],
["wait", "1000"],
["screenshot", "step1.png"],
["find", "role", "button", "click", "--name", "Next"],
["wait", "--url", "**/step2"],
["screenshot", "step2.png"]
];
console.log(JSON.stringify(commands));
Run with:
bash
node automation.js | agent-browser batch --json --bail
针对复杂的多步骤工作流,使用批量模式配合脚本:
javascript
#!/usr/bin/env node
// automation.js
const commands = [
["open", "https://example.com"],
["snapshot"],
// 处理快照,确定下一步操作...
["click", "@e5"],
["wait", "1000"],
["screenshot", "step1.png"],
["find", "role", "button", "click", "--name", "Next"],
["wait", "--url", "**/step2"],
["screenshot", "step2.png"]
];
console.log(JSON.stringify(commands));
运行方式:
bash
node automation.js | agent-browser batch --json --bail
CDP Streaming for Real-Time Monitoring
CDP流处理用于实时监控
Connect to Chrome DevTools Protocol for event streaming:
连接到Chrome DevTools Protocol进行事件流处理:
Get CDP WebSocket URL
获取CDP WebSocket地址
CDP_URL=$(agent-browser get cdp-url)
echo "CDP URL: $CDP_URL"
CDP_URL=$(agent-browser get cdp-url)
echo "CDP URL: $CDP_URL"
Or connect directly to CDP port
或直接连接到CDP端口
agent-browser connect 9222
agent-browser connect 9222
Enable runtime streaming
启用运行时流处理
agent-browser stream enable --port 9223
agent-browser stream status
agent-browser stream enable --port 9223
agent-browser stream status
... perform actions, stream events to ws://localhost:9223 ...
... 执行操作,事件将流到ws://localhost:9223 ...
agent-browser stream disable
agent-browser stream disable
Re-download Chrome for Testing
重新下载Chrome for Testing
Or specify custom Chrome path
或指定自定义Chrome路径
export CHROME_PATH=/path/to/chrome
agent-browser open
export CHROME_PATH=/path/to/chrome
agent-browser open
Use snapshot to see available refs
使用快照查看可用引用
agent-browser snapshot -i
agent-browser snapshot -i
Wait for element before interacting
等待元素加载后再交互
agent-browser wait "#dynamic-element"
agent-browser click "#dynamic-element"
agent-browser wait "#dynamic-element"
agent-browser click "#dynamic-element"
Use semantic selectors for robustness
使用语义选择器提高鲁棒性
agent-browser find role button click --name "Submit"
agent-browser find role button click --name "Submit"
List all active sessions
列出所有活跃会话
Close specific session
关闭特定会话
agent-browser close --all
agent-browser close --all
Get CDP URL for DevTools connection
获取用于连接DevTools的CDP地址
agent-browser get cdp-url
agent-browser get cdp-url
View network activity
查看网络活动
agent-browser network requests
agent-browser network requests
Enable HAR recording
启用HAR录制
agent-browser network har start
agent-browser network har start
... actions ...
... 执行操作 ...
agent-browser network har stop debug.har
agent-browser network har stop debug.har
Clipboard Access Issues
剪贴板访问问题
On Linux, clipboard requires
or
:
bash
sudo apt-get install xclip
bash
sudo apt-get install xclip
sudo apt-get install xsel
sudo apt-get install xsel
Environment Variables
环境变量
Custom Chrome binary
自定义Chrome二进制文件路径
export CHROME_PATH=/Applications/Brave Browser.app/Contents/MacOS/Brave Browser
export CHROME_PATH=/Applications/Brave Browser.app/Contents/MacOS/Brave Browser
Custom user data directory
自定义用户数据目录
export CHROME_USER_DATA_DIR=~/.config/agent-browser
export CHROME_USER_DATA_DIR=~/.config/agent-browser
Headless mode (default)
无头模式(默认开启)
export CHROME_HEADLESS=true
export CHROME_HEADLESS=true
export CHROME_HEADLESS=false
export CHROME_HEADLESS=false
Best Practices for AI Agents
AI Agent最佳实践
- Use snapshots first: Always get to understand page structure before acting
- Prefer refs over selectors: Use style refs from snapshots for stability
- Use semantic locators:
find role button --name "Submit"
is more resilient than CSS selectors
- Wait strategically: Add commands for dynamic content before interacting
- Batch when possible: Use mode to reduce per-command overhead
- Handle errors: Use in batch mode to stop on first error
- Clean up: Always sessions when done
- Screenshot for verification: Take screenshots at key steps for debugging
- Use labels for tabs: Assign meaningful labels when opening multiple tabs
- 先使用快照:在执行操作前,始终运行了解页面结构
- 优先使用引用而非选择器:使用快照中的风格引用以保证稳定性
- 使用语义定位符:
find role button --name "Submit"
比CSS选择器更具韧性
- 合理使用等待:在交互动态内容前添加命令
- 尽可能使用批量模式:使用模式减少单命令开销
- 处理错误:在批量模式中使用参数在首次出错时停止
- 清理会话:完成操作后务必执行关闭会话
- 截图验证:在关键步骤截图用于调试
- 为标签页添加标签:打开多个标签页时分配有意义的标签
Essential commands for AI agents
AI Agent核心命令
agent-browser open <url> # Start
agent-browser snapshot # Get structure with refs
agent-browser click @eN # Interact with ref
agent-browser find role button click --name "Text" # Semantic
agent-browser wait --text "Success" # Wait for content
agent-browser screenshot result.png # Verify
agent-browser get text @eN # Extract
agent-browser eval "JS" # Complex extraction
agent-browser batch "cmd1" "cmd2" # Multi-step
agent-browser close # Cleanup
agent-browser open <url> # 启动浏览器
agent-browser snapshot # 获取带引用的页面结构
agent-browser click @eN # 通过引用交互元素
agent-browser find role button click --name "Text" # 语义定位交互
agent-browser wait --text "Success" # 等待内容出现
agent-browser screenshot result.png # 截图验证
agent-browser get text @eN # 提取文本
agent-browser eval "JS" # 复杂数据提取
agent-browser batch "cmd1" "cmd2" # 多步骤批量执行
agent-browser close # 清理会话