mcpField
A
agent-browser-commands

agent-browser-commands

github.com/owenleezyAgent workflows456 installsUpdated 31w ago
Repository

About agent-browser-commands

agent-browser-commands is an internal command reference for browser automation with agent-browser. It covers navigation, page interaction, debugging, networking, sessions, and device emulation, and points automation tasks to the agent-browser skill as the entry point.

Key features

  1. 01Navigation and tab management
  2. 02Discover and interact with page elements
  3. 03Screenshots, PDFs, and diffs
  4. 04Inspect and mock network requests
  5. 05Sessions, auth, and batch execution
  6. 06Device and media emulation

Use cases

  1. 01Look up browser automation commands
  2. 02Run form operations and multi-step page flows
  3. 03Debug network or page errors
  4. 04Perform visual regression and device-emulation tests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/owenleezy/agent-browser-skill --skill agent-browser-commands

After installing, type/agent-browser-commandsin Claude Code to confirm it loaded.

Details

From the project README

Agent Browser — Command Reference

Internal reference. For browser automation tasks, use agent-browser skill as entry point.


Navigation

CommandDescription适用场景
open <url>Navigate to URL (supports chrome:// and chrome-extension://)所有任务起点
back / forwardBrowser history多页流程回溯
reloadRefresh page强制刷新状态
closeClose browser任务结束清理

Discovery

CommandDescription适用场景
snapshotAccessibility tree with refs获取交互元素引用
snapshot -iInteractive elements only聚焦可操作元素
snapshot -cCompact (less noise)大页面减少输出噪音
snapshot -d <n>Limit tree depth只看顶层结构
snapshot -s <sel>Scope to CSS selector弹窗/局部区域聚焦

Interaction

CommandDescription适用场景
click @e1Click element按钮/链接触发
dblclick @e1Double-click element可编辑单元格/选中文本
fill @e1 "text"Clear and fill input表单输入(替换原值)
type @e1 "text"Type without clearing (appends)追加内容/受控组件
keyboard type "text"Type into focused element — fires keydown/keypress/input/keyup per character, but does NOT reliably trigger document-level keydown listeners; use eval dispatchEvent(new KeyboardEvent(...)) for document-scoped event handlers焦点已在目标时输入
keyboard inserttext "text"Insert text bypassing ALL key events (no keydown/keypress/keyup fired)绕过键盘事件拦截直接插入文本
press <key>Press named key: Enter, Tab, Control+a, ArrowDown提交表单/快捷键/方向键
focus @e1Focus element聚焦后再 keyboard type
check @e1 / uncheck @e1Checkbox/radio复选框/单选操作
select @e1 "option"Dropdown selection<select> 下拉菜单
hover @e1Mouse hover触发悬停菜单/Tooltip
drag @e1 @e2Drag source element onto target — uses Playwright's pointer-based drag; works for mouse-event draggable libraries (Sortable.js, jQueryUI). Does NOT dispatch HTML5 DragEvent (dragstart/dragover/drop); for HTML5 Drag API use eval to dispatch DragEvent manually看板排序/指针拖拽
upload @e1 <file>Upload file文件上传表单
download @e1 <path>Download file by clicking element导出按钮触发下载
scroll downScroll page (up/down/left/right)触发懒加载/加载更多
scroll down --selector ".modal"Scroll within a specific container弹窗内容滚动
scrollintoview @e1Scroll element into view元素不在视口时点击前
Dialog
CommandDescription适用场景
dialog acceptAccept alert/confirm dialog确认操作类弹窗
dialog accept "text"Accept prompt dialog with inputPrompt 输入后确认
dialog dismissDismiss/cancel dialog取消操作/关闭 alert
dialog statusCheck if a dialog is currently open断言弹窗是否存在

Mouse (fine control)

Dispatches pointer/mouse events at pixel coordinates. Use for canvas, drawing apps, and CSS/pointer-event-based draggable components. Does NOT trigger HTML5 Drag API events (dragstart/dragover/drop) — those require eval DragEvent.

CommandDescription适用场景
mouse move <x> <y>Move mouse to coordinatesCanvas/绘图应用
mouse down [btn]Mouse button down拖拽起点
mouse up [btn]Mouse button up拖拽终点
mouse wheel <dy> [dx]Scroll wheel精确滚动量控制

Get Info

CommandDescription适用场景
get text @e1Get element text断言显示内容
get html @e1Get inner HTML复杂结构检查
get value @e1Get input value表单当前值验证
get attr @e1 hrefGet attribute链接/data属性检查
get title / get urlPage info导航后路由验证
get count "selector"Count matching elements列表条目数量断言
get box @e1Bounding box (x, y, width, height)精确坐标/截图裁剪
get styles @e1Computed stylesCSS 样式调试
get cdp-urlCDP WebSocket URL for the active page高级 CDP 调试

State Check

CommandDescription适用场景
is visible @e1Check if visible元素显示断言
is enabled @e1Check if enabled按钮可交互断言
is checked @e1Check if checked复选框状态断言

Waiting

CommandDescription适用场景
wait @e1Wait for element to appear异步内容渲染
wait @e1 --state hiddenWait for element to disappearLoading spinner 消失
wait @e1 --state detachedWait for element to be removed from DOM弹窗关闭后继续
wait 1000Wait millisecondsCSS 过渡动画完成
wait --load networkidleWait for network to be idle页面加载/导航后
wait --url "**/dashboard"Wait for URL to match pattern登录后跳转验证
wait --fn "window.ready"Wait for JavaScript expression to be truthy自定义加载完成信号
wait --text "Welcome"Wait for text to appear on page异步文字渲染
wait --download [path]Wait for a download to complete触发下载后等待完成

Capture

CommandDescription适用场景
screenshot [path]Take screenshot当前视口快照
screenshot --fullFull page screenshot完整页面记录/证据
screenshot --annotateAnnotated screenshot with numbered labelsBug报告/文档截图
pdf <path>Save as PDF生成可打印报告

Screenshot options: --screenshot-dir <path> (default dir), --screenshot-quality <0-100> (JPEG), --screenshot-format png|jpeg


Diff & Visual Regression

diff snapshot
agent-browser diff snapshot                         # vs last snapshot in session
agent-browser diff snapshot --baseline before.txt   # vs saved snapshot file
agent-browser diff snapshot -s ".sidebar"           # scope to selector
agent-browser diff snapshot -c -d 3                 # compact + depth limit

适用场景:DOM 结构变化检测,前后对比

diff screenshot
agent-browser diff screenshot --baseline before.png
agent-browser diff screenshot --baseline before.png --output diff.png --threshold 0.1
agent-browser diff screenshot --baseline before.png -s "#main-content" --full

适用场景:视觉回归测试,--threshold 0~1(默认 0.1,越小越严格)

diff url
agent-browser diff url https://staging.example.com https://prod.example.com
agent-browser diff url https://v1.example.com https://v2.example.com --screenshot --full
agent-browser diff url <u1> <u2> --wait-until networkidle

适用场景:跨环境/版本对比,--screenshot 同时对比截图


Debug

CommandDescription适用场景
inspectOpen Chrome DevTools (CLI still works)交互式调试
consoleView console logs查看 JS 输出
console --pattern "err"Filter console logs快速定位错误日志
console --clearClear console log buffer重置观察窗口
errorsView JavaScript errors最先查,覆盖 80% 问题
errors --clearClear error buffer重置错误计数
highlight <sel>Highlight element visually可视化确认定位
network requestsView all network requests全量 API 调用记录
network requests --filter "api"Filter by URL pattern聚焦特定接口
network requests --type xhr,fetchFilter by resource type只看 XHR/Fetch
network requests --method POSTFilter by HTTP method只看写操作
network requests --status 4xxFilter by status code快速找失败请求
network requests --clearClear network log重置记录
network request <requestId>View full request + response body查完整 payload
network har start [path]Start HAR recording完整网络追踪起点
network har stopStop and save HAR file导出供 DevTools 分析
trace start [path]Start Playwright trace recordingPlaywright 调试追踪
trace stopStop trace用 Playwright Trace Viewer 打开
profiler start [path]Start Chrome DevTools profiler性能分析
profiler stopStop profiler导出性能报告
record start <path> [url]Start video recording (WebM)录制演示/Bug 复现
record stopStop and save video保存视频
record restart <path> [url]Stop current + start new recording重新录制(重拍)
eval "JS code"Execute JavaScript自定义查询/状态注入
clipboard readRead clipboard content验证复制结果
clipboard write "text"Write to clipboard注入剪贴板数据
clipboard copy <sel>Copy element text to clipboard提取内容
clipboard paste <sel>Paste clipboard into element粘贴到输入框

Network Mocking

CommandDescription适用场景
network route "**/*.png" --abortBlock matching requests屏蔽图片/广告加速加载
network route "**/api/**" --body '{"ok":true}'Mock response body测试特定 API 响应
network unroute [url]Remove route (all if no url)恢复真实网络

Storage

CommandDescription适用场景
cookiesView all cookies会话状态检查
cookies set <name> <val> --domain example.com --secure --httpOnlySet cookie注入 Auth 令牌
cookies clearClear all cookies重置会话状态
storage localView localStorage查看持久化数据
storage local get <key>Get localStorage key读取特定 key
storage local set <key> <val>Set localStorage key注入 token/配置
storage local clearClear localStorage重置前端状态
storage session get <key>SessionStorage (same API)会话级数据操作

Tabs

CommandDescription适用场景
tab newOpen new tab多标签流程
tab listList all tabs in current browser context查看已知标签
tab <n>Switch to tab by index (0-based)切换到目标标签
tab close <n>Close tab by index关闭辅助标签

target="_blank" 限制:点击 target="_blank" 链接时,浏览器可能在新的 BrowserContext 中打开,agent-browser 的 tab list 只跟踪当前 context 内的标签。如果新标签没有出现在 tab list 中,改用 tab new + open <url> 手动管理。


Sessions

CommandDescription适用场景
sessionShow current session name确认当前会话
session listList active sessions多会话并发查看

Auth Vault

Save and reuse login credentials — avoids manual login in every E2E run:

# Save once
agent-browser auth save myapp --url http://localhost:5173/login --username admin --password secret

# Reuse in any test (auto-fills and submits login form)
agent-browser auth login myapp

# Manage
agent-browser auth list
agent-browser auth show myapp
agent-browser auth delete myapp

Credentials are encrypted with AES-256-GCM (AGENT_BROWSER_ENCRYPTION_KEY). Prefer --password-stdin over --password to avoid shell history exposure.


Batch Execution

Execute multiple commands from stdin as a JSON array — more efficient than sequential shell calls:

echo '[["fill","@e1","[email protected]"],["fill","@e2","pass"],["click","@e3"]]' | agent-browser batch
agent-browser batch --bail   # stop on first error (default: continue all)

Confirmation

For actions that require explicit approval (when --confirm-actions is set):

CommandDescription适用场景
confirm <id>Approve a pending action审批写操作
deny <id>Deny a pending action拒绝危险操作

Device / Emulation

CommandDescription适用场景
set viewport <w> <h>Set viewport size响应式测试
set viewport <w> <h> <scale>Set viewport with device pixel ratioRetina 屏测试
set device "iPhone 15 Pro"Preset device emulation移动端完整模拟
set geo <lat> <lng>Set geolocation地理位置功能测试
set offline [on|off]Toggle offline mode (always restore with set offline off)PWA/离线模式测试
set headers <json>Set HTTP headers scoped to page origin注入 Authorization
set credentials <user> <pass>HTTP basic authBasic Auth 站点
set media darkDark mode暗色主题测试
set media dark reduced-motionDark + reduced motion无障碍测试

iOS Simulator (requires Xcode + Appium): use -p ios flag

agent-browser -p ios open http://localhost:3000
agent-browser -p ios --device "iPhone 15 Pro" snapshot
agent-browser -p ios device list
agent-browser -p ios swipe up

Setup

CommandDescription适用场景
installDownload Chromium (first time setup)首次安装
install --with-depsAlso install system dependencies (Linux)Linux CI 环境
upgradeUpgrade agent-browser to latest (npm only; Homebrew: brew upgrade agent-browser)版本更新

Semantic Locators (find)

Preferred over CSS selectors — survives UI refactoring:

agent-browser find role button click --name "Submit"
agent-browser find role link click --name "Learn More"
agent-browser find role button click --name "Submit" --exact   # exact name match
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "[email protected]"
agent-browser find placeholder "Search..." type "query"
agent-browser find testid "submit-button" click
agent-browser find alt "Company logo" click
agent-browser find first "button.primary" click
agent-browser find last "a.link" click
agent-browser find nth 2 ".card" hover     # 0-based index

Valid find subcommands: role, text, label, placeholder, alt, title, testid, first, last, nth ❌ find ref does NOT exist.

Using Refs from Snapshot

snapshot returns refs like [ref=e3]. These can be used directly with action commands — NOT via find:

# ✅ Direct ref usage
agent-browser click @e3
agent-browser fill @e3 "hello"
agent-browser hover @e3

# ✅ Refs in assertions
agent-browser is visible @e3
agent-browser get text @e3
agent-browser get value @e3

# ❌ Wrong — ref is not a find subcommand
agent-browser find ref e3 fill "hello"

Global Options

OptionDescription
--headedShow browser window; also via AGENT_BROWSER_HEADED=1
--engine chrome|lightpandaBrowser engine; also via AGENT_BROWSER_ENGINE
-p, --provider <name>Browser provider: ios, browserbase, kernel, browseruse, browserless
--cdp <port>Connect to Chrome via CDP
--auto-connectAuto-discover running Chrome
--profile <path>Persistent browser profile (auth reuse)
--session <name>Isolated session
--session-name <name>Auto-save/restore cookies & localStorage
--state <path>Load storage state from JSON
--download-path <path>Default download directory; also via AGENT_BROWSER_DOWNLOAD_PATH
--headers '{"Authorization":"Bearer token"}'Auth headers
--proxy "http://127.0.0.1:7890"Proxy server (also reads HTTP_PROXY / HTTPS_PROXY / ALL_PROXY env vars as fallback)
--proxy-bypass "localhost,*.internal"Bypass proxy (also reads NO_PROXY env var)
--color-scheme dark|lightColor scheme preference
--ignore-https-errorsIgnore TLS certificate errors
--allow-file-accessAllow file:// URL access
--user-agent <ua>Custom User-Agent
--allowed-domains <list>Restrict to approved domains (security); --domain-allowlist is an alias
--action-policy <path>JSON file defining allowed/blocked action categories
--confirm-actions <list>Action categories requiring confirmation
--confirm-interactiveInteractive confirmation prompts in TTY
--content-boundariesWrap page output in boundary markers (helps parse --max-output)
--max-output <chars>Truncate page output to N chars; also via AGENT_BROWSER_MAX_OUTPUT
--jsonJSON output
--full / -fFull page (screenshot)
--annotateAnnotated output
--debugDebug output
Key Environment Variables
VariableDescription
AGENT_BROWSER_HEADED=1Show browser window
AGENT_BROWSER_ENGINE=chrome|lightpandaBrowser engine (chrome is default)
AGENT_BROWSER_NATIVE=1⚠️ Legacy alias — accepted but undocumented in 0.22+; prefer omitting (chrome engine is default)
AGENT_BROWSER_DEFAULT_TIMEOUTDefault action timeout in ms (default: 25000)
AGENT_BROWSER_MAX_OUTPUTMax characters for page output
AGENT_BROWSER_STREAM_PORTEnable WebSocket streaming on port (e.g., 9223)
AGENT_BROWSER_IDLE_TIMEOUT_MSAuto-shutdown daemon after N ms of inactivity
AGENT_BROWSER_ENCRYPTION_KEY64-char hex key for AES-256-GCM Auth Vault encryption
AGENT_BROWSER_SCREENSHOT_DIRDefault screenshot output directory

Comments

Markdown supported