From 97cbcf3eb315c439615d91eafd63e8e1139d6e0d Mon Sep 17 00:00:00 2001 From: wehub-resource-sync Date: Mon, 13 Jul 2026 10:26:45 +0000 Subject: [PATCH] docs: make Chinese README the default --- README.md | 856 +++++++++++++++++++++++++++--------------------------- 1 file changed, 431 insertions(+), 425 deletions(-) diff --git a/README.md b/README.md index a55aac3..c44796b 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,54 @@ + +> [!NOTE] +> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。 +> [English](./README.en.md) · [原始项目](https://github.com/vercel-labs/agent-browser) · [上游 README](https://github.com/vercel-labs/agent-browser/blob/HEAD/README.md) +> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。 + # agent-browser -Browser automation CLI for AI agents. Fast native Rust CLI. +面向 AI 智能体的浏览器自动化 CLI。原生 Rust CLI,运行快速。 [![skills.sh](https://skills.sh/b/vercel-labs/agent-browser)](https://skills.sh/vercel-labs/agent-browser) -## Installation +## 安装 -### Global Installation (recommended) +### 全局安装(推荐) -Installs the native Rust binary: +安装原生 Rust 二进制文件: ```bash npm install -g agent-browser agent-browser install # Download Chrome from Chrome for Testing (first time only) ``` -### Project Installation (local dependency) +### 项目安装(本地依赖) -For projects that want to pin the version in `package.json`: +适用于希望在 `package.json` 中固定版本的项目: ```bash npm install agent-browser agent-browser install ``` -Then use via `package.json` scripts or by invoking `agent-browser` directly. +随后可通过 `package.json` 脚本使用,或直接调用 `agent-browser`。 -### Homebrew (macOS) +### Homebrew(macOS) ```bash brew install agent-browser agent-browser install # Download Chrome from Chrome for Testing (first time only) ``` -### Cargo (Rust) +### Cargo(Rust) ```bash cargo install agent-browser agent-browser install # Download Chrome from Chrome for Testing (first time only) ``` -### From Source +### 从源码构建 -Requires Node.js 24+, pnpm 11+, and Rust. +需要 Node.js 24+、pnpm 11+ 和 Rust。 ```bash git clone https://github.com/vercel-labs/agent-browser @@ -54,33 +60,33 @@ pnpm link --global # Makes agent-browser available globally agent-browser install ``` -### Linux Dependencies +### Linux 依赖 -On Linux, install system dependencies: +在 Linux 上,请安装系统依赖: ```bash agent-browser install --with-deps ``` -This exits nonzero if the package manager cannot install every required browser library. +如果包管理器无法安装所有必需的浏览器库,进程将以非零状态退出。 -### Updating +### 更新 -Upgrade to the latest version: +升级到最新版本: ```bash agent-browser upgrade ``` -Detects your installation method (npm, Homebrew, or Cargo) and runs the appropriate update command automatically. +自动检测你的安装方式(npm、Homebrew 或 Cargo),并运行相应的更新命令。 -### Requirements +### 系统要求 -- **Chrome** - Run `agent-browser install` to download Chrome from [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) (Google's official automation channel). Existing Chrome, Brave, Playwright, and Puppeteer installations are detected automatically. No Playwright or Node.js required for the daemon. -- **Node.js 24+ and pnpm 11+** - Only needed when building from source. -- **Rust** - Only needed when building from source (see From Source above). +- **Chrome** — 运行 `agent-browser install` 从 [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/)(Google 官方自动化渠道)下载 Chrome。现有的 Chrome、Brave、Playwright 和 Puppeteer 安装会被自动检测。守护进程(daemon)无需 Playwright 或 Node.js。 +- **Node.js 24+ 和 pnpm 11+** — 仅在从源码构建时需要。 +- **Rust** — 仅在从源码构建时需要(参见上文「从源码构建」)。 -## Quick Start +## 快速入门 ```bash agent-browser open example.com @@ -92,11 +98,11 @@ agent-browser screenshot page.png agent-browser close ``` -Clicks fail early when another element covers the target's click point, for example a consent banner or modal. Dismiss or interact with the reported covering element, then take a fresh snapshot before retrying the original ref. +当其他元素遮挡目标的点击位置时(例如同意横幅或模态框),点击会提前失败。请先关闭或与报告中的遮挡元素交互,然后重新获取快照,再重试原始 ref。 -Headless Chromium screenshots hide native scrollbars for consistent image output. Pass `--hide-scrollbars false` when launching to keep native scrollbars visible. +无头(Headless)Chromium 截图会隐藏原生滚动条,以保证图像输出一致。启动时传入 `--hide-scrollbars false` 可保留原生滚动条可见。 -### Traditional Selectors (also supported) +### 传统选择器(同样支持) ```bash agent-browser click "#submit" @@ -104,9 +110,9 @@ agent-browser fill "#email" "test@example.com" agent-browser find role button click --name "Submit" ``` -## Commands +## 命令 -### Core Commands +### 核心命令 ```bash agent-browser open # Launch browser (no navigation); stays on about:blank @@ -147,7 +153,7 @@ agent-browser chat "" # AI chat: natural language browser contro agent-browser chat # AI chat: interactive REPL mode ``` -### Get Info +### 获取信息 ```bash agent-browser get text # Get text content @@ -162,7 +168,7 @@ agent-browser get box # Get bounding box agent-browser get styles # Get computed styles ``` -### Read Agent-Friendly Text +### 读取对智能体友好的文本 ```bash agent-browser read @@ -175,11 +181,11 @@ agent-browser read example.com/article --require-md agent-browser read https://example.com/article --json ``` -`read` fetches a URL without launching Chrome. Omit the URL to read the rendered DOM of the active tab in the current browser session, including browser auth state and client-side updates. Explicit URL reads send `Accept: text/markdown` by default, try the same URL with `.md` appended when the first response is not markdown, walk ancestor paths toward `/` to find the nearest `llms.txt` for a matching docs link, print markdown or plain text when available, and fall back to readable text extracted from HTML. `--llms` and `--require-md` with no URL use the active tab URL because they depend on HTTP resources. `read` does not read `llms-full.txt` unless you ask for it. +`read` 可在不启动 Chrome 的情况下获取 URL。省略 URL 时,会读取当前浏览器会话中活动标签页的渲染后 DOM,包括浏览器认证状态和客户端更新。显式指定 URL 读取时,默认发送 `Accept: text/markdown`;若首次响应不是 markdown,可尝试在同一 URL 后追加 `.md`;沿祖先路径向 `/` 遍历,以查找最近的匹配文档链接 `llms.txt`;在可用时输出 markdown 或纯文本,否则回退到从 HTML 提取的可读文本。未指定 URL 时,`--llms` 和 `--require-md` 使用活动标签页 URL,因为它们依赖 HTTP 资源。除非你明确要求,否则 `read` 不会读取 `llms-full.txt`。 -Options: `--raw` prints the response body without HTML extraction, `--require-md` fails unless the server returns `Content-Type: text/markdown`, `--outline` prints a compact heading outline for one page, `--llms index` prints a compact nearest-ancestor `llms.txt` link list, `--llms full` reads the nearest-ancestor `llms-full.txt`, `--filter ` narrows page sections, llms links/sections, or outline headings, and `--timeout ` changes the request timeout. Global safeguards such as `--allowed-domains`, `--content-boundaries`, and `--max-output` also apply to read fetches and output. +选项:`--raw` 直接打印响应体,不进行 HTML 提取;`--require-md` 除非服务器返回 `Content-Type: text/markdown` 否则失败;`--outline` 打印单页的紧凑标题大纲;`--llms index` 打印紧凑的最近祖先 `llms.txt` 链接列表;`--llms full` 读取最近祖先 `llms-full.txt`;`--filter ` 可缩小页面区块、llms 链接/区块或大纲标题范围;`--timeout ` 可更改请求超时。`--allowed-domains`、`--content-boundaries` 和 `--max-output` 等全局保护措施同样适用于读取请求与输出。 -### Check State +### 检查状态(Check State) ```bash agent-browser is visible # Check if visible @@ -187,7 +193,7 @@ agent-browser is enabled # Check if enabled agent-browser is checked # Check if checked ``` -### Find Elements (Semantic Locators) +### 查找元素(语义定位器 Semantic Locators) ```bash agent-browser find role [value] # By ARIA role @@ -202,11 +208,11 @@ agent-browser find last [value] # Last match agent-browser find nth [value] # Nth match ``` -**Actions:** `click`, `fill`, `type`, `hover`, `focus`, `check`, `uncheck`, `text` +**操作:** `click`、`fill`、`type`、`hover`、`focus`、`check`、`uncheck`、`text` -**Options:** `--name ` (filter role by accessible name), `--exact` (require exact text match) +**选项:** `--name `(按可访问名称 accessible name 筛选角色 role)、`--exact`(要求精确文本匹配) -**Examples:** +**示例:** ```bash agent-browser find role button click --name "Submit" @@ -216,7 +222,7 @@ agent-browser find first ".item" click agent-browser find nth 2 "a" text ``` -### Wait +### 等待(Wait) ```bash agent-browser wait # Wait for element to be visible @@ -231,11 +237,11 @@ agent-browser wait --fn "!document.body.innerText.includes('Loading...')" agent-browser wait "#spinner" --state hidden ``` -**Load states:** `load`, `domcontentloaded`, `networkidle` +**加载状态:** `load`、`domcontentloaded`、`networkidle` -### Batch Execution +### 批量执行(Batch Execution) -Execute multiple commands in a single invocation. Commands can be passed as quoted arguments or piped as JSON via stdin. This avoids per-command process startup overhead when running multi-step workflows. +在单次调用中执行多条命令。命令可作为带引号的参数传入,或通过 stdin 以 JSON 管道方式传入。这可以避免在多步骤工作流中逐条执行命令时的进程启动开销。 ```bash # Argument mode: each quoted argument is a full command @@ -253,7 +259,7 @@ echo '[ ]' | agent-browser batch --json ``` -### Clipboard +### 剪贴板(Clipboard) ```bash agent-browser clipboard read # Read text from clipboard @@ -262,7 +268,7 @@ agent-browser clipboard copy # Copy current selection (Ctrl agent-browser clipboard paste # Paste from clipboard (Ctrl+V) ``` -### Mouse Control +### 鼠标控制(Mouse Control) ```bash agent-browser mouse move # Move mouse @@ -271,7 +277,7 @@ agent-browser mouse up [button] # Release button agent-browser mouse wheel [dx] # Scroll wheel ``` -### Browser Settings +### 浏览器设置(Browser Settings) ```bash agent-browser set viewport [scale] # Set viewport size (scale for retina, e.g. 2) @@ -283,7 +289,7 @@ agent-browser set credentials

# HTTP basic auth agent-browser set media [dark|light] # Emulate color scheme ``` -### Cookies & Storage +### Cookie 与存储(Cookies & Storage) ```bash agent-browser cookies # Get all cookies @@ -300,7 +306,7 @@ agent-browser storage local clear # Clear all agent-browser storage session # Same for sessionStorage ``` -### Network +### 网络(Network) ```bash agent-browser network route # Intercept requests @@ -318,7 +324,7 @@ agent-browser network har start # Start HAR recording agent-browser network har stop [output.har] # Stop and save HAR (temp path if omitted) ``` -### Tabs & Windows +### 标签页与窗口(Tabs & Windows) ```bash agent-browser tab # List tabs (shows `tabId` and optional label) @@ -329,9 +335,9 @@ agent-browser tab close [t|label] # Close a tab (defaults to active agent-browser window new # New window ``` -Tab ids are stable strings of the form `t1`, `t2`, `t3`. They're never reused within a session, so scripts and agents can keep referring to the same tab even after other tabs are opened or closed. Positional integers like `tab 2` are **not** accepted; the `t` prefix disambiguates handles from indices and mirrors the `@e1` convention used for element refs. +标签页 id 是形如 `t1`、`t2`、`t3` 的稳定字符串。在同一会话内它们不会被复用,因此即使其他标签页被打开或关闭,脚本和 agent 仍可继续引用同一标签页。像 `tab 2` 这样的位置整数**不**被接受;`t` 前缀用于将句柄与索引区分开,并与元素引用所使用的 `@e1` 约定保持一致。 -You can also assign a memorable label (`docs`, `app`, `admin`) and use it interchangeably with the id. Labels are never auto-generated and never rewritten on navigation — they're yours to name and keep: +你也可以指定一个易记的标签(`docs`、`app`、`admin`),并与 id 互换使用。标签不会自动生成,也不会在导航时被重写——由你命名并保留: ```bash agent-browser tab new --label docs https://docs.example.com @@ -341,14 +347,14 @@ agent-browser click @e3 # click uses docs's refs agent-browser tab close docs # close by label ``` -### Frames +### 框架(Frames) ```bash agent-browser frame # Switch to iframe agent-browser frame main # Back to main frame ``` -### Dialogs +### 对话框(Dialogs) ```bash agent-browser dialog accept [text] # Accept (with optional prompt text) @@ -356,11 +362,11 @@ agent-browser dialog dismiss # Dismiss agent-browser dialog status # Check if a dialog is currently open ``` -By default, `alert` and `beforeunload` dialogs are automatically accepted so they never block the agent. `confirm` and `prompt` dialogs still require explicit handling. Use `--no-auto-dialog` (or `AGENT_BROWSER_NO_AUTO_DIALOG=1`) to disable automatic handling. +默认情况下,`alert` 和 `beforeunload` 对话框会自动接受,因此不会阻塞 agent。`confirm` 和 `prompt` 对话框仍需显式处理。使用 `--no-auto-dialog`(或 `AGENT_BROWSER_NO_AUTO_DIALOG=1`)可禁用自动处理。 -When a JavaScript dialog is pending, all command responses include a `warning` field with the dialog type and message. +当 JavaScript 对话框处于待处理状态时,所有命令响应都会包含一个 `warning` 字段,其中带有对话框类型和消息。 -### Diff +### 差异对比(Diff) ```bash agent-browser diff snapshot # Compare current vs last snapshot @@ -409,9 +415,9 @@ agent-browser pushstate # SPA client-side nav; auto-detects window # falls back to history.pushState + popstate ``` -### Pre-navigation setup +### 导航前准备 -Some flows (SSR debug, auth cookies for protected origins, init scripts) need state set up *before* the first navigation. Use `open` with no URL to launch the browser, then stage cookies / routes / init scripts, then navigate. `batch` sends it all in one CLI call: +部分流程(SSR 调试、受保护来源的 auth cookies、init scripts)需要在首次导航*之前*完成状态设置。使用不带 URL 的 `open` 启动浏览器,然后配置 cookies / routes / init scripts,再进行导航。`batch` 可在一次 CLI 调用中完成上述全部操作: ```bash agent-browser batch \ @@ -421,11 +427,11 @@ agent-browser batch \ '["navigate","http://localhost:3000/target"]' ``` -Without `batch` the same sequence is three commands that all reuse the same daemon (fast, but not one turn). +若不使用 `batch`,相同流程需要三条命令,但都会复用同一 daemon(速度快,但不是一轮完成)。 ### React / Web Vitals -Agent-browser ships with first-class React introspection and universal Web Vitals metrics. The React commands need the React DevTools hook installed at launch; Web Vitals and pushstate are framework-agnostic. +agent-browser 内置一流的 React 内省(introspection)和通用的 Web Vitals 指标。React 命令需要在启动时安装 React DevTools hook;Web Vitals 和 pushstate 与框架无关。 ```bash agent-browser open --enable react-devtools # Launch with React hook installed @@ -438,10 +444,10 @@ agent-browser react suspense [--only-dynamic] [--json] # Suspense boundaries + agent-browser vitals [url] [--json] # LCP/CLS/TTFB/FCP/INP + hydration summary ``` -Each `react ...` subcommand requires `--enable react-devtools` to have been passed at launch (the React DevTools `installHook.js` is embedded in the binary). Without it the commands error with `React DevTools hook not installed -- relaunch with --enable react-devtools`. +每个 `react ...` 子命令都要求启动时传入 `--enable react-devtools`(React DevTools `installHook.js` 已嵌入二进制文件)。未传入时,命令会报错:`React DevTools hook not installed +- relaunch with --enable react-devtools`。 -Works on any React app — Next.js, Remix, Vite+React, CRA, TanStack Start, React Native Web, etc. `vitals` and `pushstate` are framework-agnostic. `vitals` prints a summary by default; pass `--json` for the full structured payload. +适用于任意 React 应用 — Next.js、Remix、Vite+React、CRA、TanStack Start、React Native Web 等。`vitals` 和 `pushstate` 与框架无关。`vitals` 默认打印摘要;传入 `--json` 可获取完整的结构化 payload。 ### Init scripts @@ -464,7 +470,7 @@ agent-browser doctor --offline --quick # Skip network probes and the live launc agent-browser mcp # Start an MCP stdio server ``` -`doctor` checks your environment, Chrome install, daemon state, config files, encryption key, providers, network reachability, and runs a live headless browser launch test. Stale socket/pid sidecar files are auto-cleaned. Output is also available as `--json` for agents. +`doctor` 会检查你的环境、Chrome 安装、daemon 状态、配置文件、加密密钥、providers、网络可达性,并运行一次实时的无头浏览器启动测试。过期的 socket/pid sidecar 文件会自动清理。输出也可通过 `--json` 供 agents 使用。 ### Skills @@ -477,7 +483,7 @@ agent-browser skills get --all # Output every skill agent-browser skills path [name] # Print skill directory path ``` -Serves bundled skill content that always matches the installed CLI version. AI agents use this to get current instructions rather than relying on cached copies. Set `AGENT_BROWSER_SKILLS_DIR` to override the skills directory path. +提供与已安装 CLI 版本始终一致的捆绑 skill 内容。AI agents 通过此方式获取最新指令,而不是依赖缓存副本。设置 `AGENT_BROWSER_SKILLS_DIR` 可覆盖 skills 目录路径。 ### MCP Server @@ -487,22 +493,22 @@ agent-browser mcp --tools all agent-browser mcp --tools core,network,react ``` -Starts a Model Context Protocol server over stdio. MCP clients launch this command as a subprocess and exchange newline-delimited JSON-RPC on stdin and stdout. The server defaults to MCP protocol 2025-11-25 and accepts older supported client protocol versions during initialization. +通过 stdio 启动 Model Context Protocol(MCP)服务器。MCP 客户端将此命令作为子进程启动,并在 stdin 与 stdout 上交换换行分隔的 JSON-RPC。服务器默认使用 MCP 协议 2025-11-25,并在初始化期间接受更早的受支持客户端协议版本。 -The default tools profile is `core`, which keeps MCP context small for everyday browser automation. Use `--tools all` for the full typed CLI parity surface, or combine profiles with commas, such as `--tools core,network,react`. +默认 tools profile 为 `core`,可保持 MCP 上下文精简,适用于日常浏览器自动化。使用 `--tools all` 可获取完整的 typed CLI 对等能力,或用逗号组合多个 profile,例如 `--tools core,network,react`。 -Profiles: +Profiles: -- `core` — Default. Navigation, snapshots, interaction, waits, reads, screenshots, JavaScript eval, close, tab basics, and profile discovery -- `network` — Network routes, request inspection, HAR, headers, credentials, offline -- `state` — Cookies, storage, auth, saved state, sessions, profiles, skills -- `debug` — Console/errors, tracing, profiling, recording, clipboard, plugins, doctor, dashboard, install, upgrade, chat, diff, batch, confirm/deny -- `tabs` — Back/forward/reload, tabs, windows, frames, dialogs -- `react` — React tree/inspect/renders/suspense, vitals, pushstate -- `mobile` — Viewport/device/geolocation/media, touch, swipe, mouse, keyboard -- `all` — Every MCP tool, including the full typed CLI parity surface +- `core` — 默认。导航、快照、交互、等待、读取、截图、JavaScript eval、close、标签页基础操作,以及 profile 发现 +- `network` — 网络 routes、请求检查、HAR、headers、credentials、offline +- `state` — Cookies、storage、auth、saved state、sessions、profiles、skills +- `debug` — Console/errors、tracing、profiling、recording、clipboard、plugins、doctor、dashboard、install、upgrade、chat、diff、batch、confirm/deny +- `tabs` — 后退/前进/刷新、tabs、windows、frames、dialogs +- `react` — React tree/inspect/renders/suspense、vitals、pushstate +- `mobile` — Viewport/device/geolocation/media、touch、swipe、mouse、keyboard +- `all` — 全部 MCP tool,包括完整的 typed CLI 对等能力 -Common tools include: +常用 tools 包括: - `agent_browser_tools_profiles` - `agent_browser_open` @@ -517,9 +523,9 @@ Common tools include: - `agent_browser_eval` - `agent_browser_close` -Each tool has typed fields such as `url`, `selector`, `text`, `key`, and `session`, so MCP clients show meaningful approval prompts instead of raw command arrays. Each tool also accepts `extraArgs` for advanced CLI flags and exact CLI parity. Tool discovery is paginated and includes read-only/open-world annotations so modern MCP clients can load the large typed surface incrementally. +每个 tool 都有类型化字段,例如 `url`、`selector`、`text`、`key` 和 `session`,因此 MCP 客户端会显示有意义的审批提示,而不是原始命令数组。每个 tool 也接受 `extraArgs`,用于高级 CLI flags 和精确的 CLI 对等。Tool 发现支持分页,并包含只读/open-world 注解,以便现代 MCP 客户端可增量加载庞大的 typed 能力面。 -Example MCP client config: +MCP 客户端配置示例: ```json { @@ -532,7 +538,7 @@ Example MCP client config: } ``` -Full parity MCP client config: +完整对等 MCP 客户端配置: ```json { @@ -545,26 +551,26 @@ Full parity MCP client config: } ``` -Tool invocations use the same config files and environment variables as the CLI. Use `session` in the tool arguments, or set `AGENT_BROWSER_SESSION`, to isolate browser state. +工具调用与 CLI 使用相同的配置文件和环境变量。在工具参数中使用 `session`,或设置 `AGENT_BROWSER_SESSION`,以隔离浏览器状态。 -## Authentication +## 身份验证 -agent-browser provides multiple ways to persist login sessions so you don't re-authenticate every run. +agent-browser 提供多种方式来持久化登录会话,这样你就不必在每次运行时都重新进行身份验证。 -### Quick summary +### 快速概览 -| Approach | Best for | Flag / Env | +| 方式 | 适用场景 | 标志 / 环境变量 | |----------|----------|------------| -| **Chrome profile reuse** | Reuse your existing Chrome login state (cookies, sessions) with zero setup | `--profile ` / `AGENT_BROWSER_PROFILE` | -| **Persistent profile** | Full browser state (cookies, IndexedDB, service workers, cache) across restarts | `--profile ` / `AGENT_BROWSER_PROFILE` | -| **Session persistence** | Auto-save/restore cookies + localStorage from a stable session key | `--session --restore` / `AGENT_BROWSER_RESTORE` | -| **Import from your browser** | Grab auth from a Chrome session you already logged into | `--auto-connect` + `state save` | -| **State file** | Load a previously saved state JSON on launch | `--state ` / `AGENT_BROWSER_STATE` | -| **Auth vault** | Store credentials locally (encrypted), login by name | `auth save` / `auth login` | +| **Chrome profile reuse** | 零配置即可复用你现有的 Chrome 登录状态(cookie、会话) | `--profile ` / `AGENT_BROWSER_PROFILE` | +| **Persistent profile** | 在重启后保留完整浏览器状态(cookie、IndexedDB、service worker、缓存) | `--profile ` / `AGENT_BROWSER_PROFILE` | +| **Session persistence** | 通过稳定的会话键自动保存/恢复 cookie 与 localStorage | `--session --restore` / `AGENT_BROWSER_RESTORE` | +| **Import from your browser** | 从你已登录的 Chrome 会话中获取身份验证信息 | `--auto-connect` + `state save` | +| **State file** | 启动时加载先前保存的状态 JSON | `--state ` / `AGENT_BROWSER_STATE` | +| **Auth vault** | 在本地存储凭据(加密),按名称登录 | `auth save` / `auth login` | -### Import auth from your browser +### 从浏览器导入身份验证信息 -If you are already logged in to a site in Chrome, you can grab that auth state and reuse it: +如果你已在 Chrome 中登录某个网站,可以获取该身份验证状态并重复使用: ```bash # 1. Launch Chrome with remote debugging enabled @@ -584,15 +590,15 @@ agent-browser --session "$SESSION" --restore --state ./my-auth.json open https:/ # From now on, --session "$SESSION" --restore auto-saves/restores this state ``` -> **Security notes:** -> - `--remote-debugging-port` exposes full browser control on localhost. Any local process can connect. Only use on trusted machines and close Chrome when done. -> - State files contain session tokens in plaintext. Add them to `.gitignore` and delete when no longer needed. For encryption at rest, set `AGENT_BROWSER_ENCRYPTION_KEY` (see [State Encryption](#state-encryption)). +> **安全说明:** +> - `--remote-debugging-port` 会在 localhost 上暴露完整的浏览器控制能力。任何本地进程都可以连接。仅在受信任的机器上使用,用完后关闭 Chrome。 +> - 状态文件以明文形式包含会话令牌。请将它们加入 `.gitignore`,并在不再需要时删除。若要对静态存储进行加密,请设置 `AGENT_BROWSER_ENCRYPTION_KEY`(参见[状态加密](#state-encryption))。 -For full details on login flows, OAuth, 2FA, cookie-based auth, and the auth vault, see the [Authentication](docs/src/app/sessions/page.mdx) docs. +有关登录流程、OAuth、2FA、基于 cookie 的身份验证以及 auth vault 的完整说明,请参阅 [Authentication](docs/src/app/sessions/page.mdx) 文档。 -## Sessions +## 会话 -Run multiple isolated browser instances: +运行多个相互隔离的浏览器实例: ```bash # Different sessions @@ -619,16 +625,16 @@ agent-browser session id --scope worktree --prefix next-dev-loop agent-browser session info --json ``` -Each session has its own: +每个会话都拥有独立的: -- Browser instance -- Cookies and storage -- Navigation history -- Authentication state +- 浏览器实例 +- Cookie 与存储 +- 导航历史 +- 身份验证状态 -## Chrome Profile Reuse +## 复用 Chrome 配置文件 -The fastest way to use your existing login state: pass a Chrome profile name to `--profile`: +使用现有登录状态的最快方式:向 `--profile` 传入 Chrome 配置文件名称: ```bash # List available Chrome profiles @@ -644,13 +650,13 @@ agent-browser --profile "Work" open https://app.example.com AGENT_BROWSER_PROFILE=Default agent-browser open https://gmail.com ``` -This copies your Chrome profile to a temp directory (read-only snapshot, no changes to your original profile), so the browser launches with your existing cookies and sessions. +这会将你的 Chrome 配置文件复制到临时目录(只读快照,不会修改原始配置文件),因此浏览器启动时会带上你现有的 cookie 和会话。 -> **Note:** On Windows, close Chrome before using `--profile ` if Chrome is running, as some profile files may be locked. +> **注意:** 在 Windows 上,如果 Chrome 正在运行,使用 `--profile ` 前请先关闭 Chrome,因为部分配置文件可能被锁定。 -## Persistent Profiles +## 持久化配置文件 -For a persistent custom profile directory that stores state across browser restarts, pass a path to `--profile`: +若要在浏览器重启后仍保留状态,请向 `--profile` 传入持久化自定义配置文件目录的路径: ```bash # Use a persistent profile directory @@ -663,19 +669,19 @@ agent-browser --profile ~/.myapp-profile open myapp.com/dashboard AGENT_BROWSER_PROFILE=~/.myapp-profile agent-browser open myapp.com ``` -The profile directory stores: +配置文件目录会存储: -- Cookies and localStorage -- IndexedDB data -- Service workers -- Browser cache -- Login sessions +- Cookie 与 localStorage +- IndexedDB 数据 +- Service Worker +- 浏览器缓存 +- 登录会话 -**Tip**: Use different profile paths for different projects to keep their browser state isolated. +**提示**:为不同项目使用不同的配置文件路径,以保持各自的浏览器状态相互隔离。 -## Session Persistence +## 会话持久化 -Use `--restore` with a stable `--session` to automatically save and restore cookies and localStorage across browser restarts: +将 `--restore` 与稳定的 `--session` 配合使用,可在浏览器重启后自动保存并恢复 cookie 与 localStorage: ```bash # Generate a stable id for this worktree and auto-save/load state @@ -689,11 +695,11 @@ agent-browser --session "$SESSION" --restore open twitter.com agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open twitter.com ``` -State is saved when the browser closes (explicit `close`, idle timeout, or daemon shutdown) and also periodically while the browser is open, so a browser window you close by hand still leaves a recent save behind. Periodic autosave waits for commands to settle, then saves at most once per `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` (default 30000; set to `0` to save only on close). Idle sessions keep saving on the same interval, so changes the page makes on its own (token refreshes, background requests) are captured too. It respects the `--restore-save` policy. +浏览器关闭时会保存状态(显式 `close`、空闲超时或守护进程关闭),在浏览器运行期间也会定期保存,因此你手动关闭的浏览器窗口仍会留下最近的保存记录。定期自动保存会等待命令执行完毕,然后最多每 `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` 保存一次(默认 30000;设为 `0` 则仅在关闭时保存)。空闲会话仍按相同间隔保存,因此页面自行产生的变更(令牌刷新、后台请求)也会被捕获。它会遵循 `--restore-save` 策略。 -### State Encryption +### 状态加密 -Encrypt saved session data at rest with AES-256-GCM: +使用 AES-256-GCM 对静态存储的会话数据进行加密: ```bash # Generate key: openssl rand -hex 32 @@ -703,43 +709,43 @@ export AGENT_BROWSER_ENCRYPTION_KEY=<64-char-hex-key> agent-browser --session secure --restore open example.com ``` -| Variable | Description | +| 变量 | 说明 | | --------------------------------- | -------------------------------------------------- | -| `AGENT_BROWSER_RESTORE` | Auto-save/load state persistence name | -| `AGENT_BROWSER_RESTORE_SAVE` | Restore save policy: `auto`, `always`, or `never` | -| `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` | Min ms between periodic autosaves (default: 30000, 0 disables) | -| `AGENT_BROWSER_NAMESPACE` | Namespace for daemon sockets and restore state | -| `AGENT_BROWSER_SESSION_NAME` | Legacy auto-save/load state persistence name | -| `AGENT_BROWSER_ENCRYPTION_KEY` | 64-char hex key for AES-256-GCM encryption | -| `AGENT_BROWSER_STATE_EXPIRE_DAYS` | Auto-delete states older than N days (default: 30) | +| `AGENT_BROWSER_RESTORE` | 自动保存/加载状态持久化名称 | +| `AGENT_BROWSER_RESTORE_SAVE` | 恢复保存策略:`auto`、`always` 或 `never` | +| `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` | 定期自动保存之间的最小毫秒数(默认:30000,0 表示禁用) | +| `AGENT_BROWSER_NAMESPACE` | 守护进程套接字与恢复状态的命名空间 | +| `AGENT_BROWSER_SESSION_NAME` | 旧版自动保存/加载状态持久化名称 | +| `AGENT_BROWSER_ENCRYPTION_KEY` | 用于 AES-256-GCM 加密的 64 字符十六进制密钥 | +| `AGENT_BROWSER_STATE_EXPIRE_DAYS` | 自动删除超过 N 天的状态(默认:30) | -## Security +## 安全 -agent-browser includes security features for safe AI agent deployments. All features are opt-in, and existing workflows are unaffected until you explicitly enable a feature: +agent-browser 包含用于安全部署 AI agent 的安全功能。所有功能均为可选启用,在你显式启用某项功能之前,现有工作流不受影响: -- **Authentication Vault**: Store credentials locally (always encrypted), reference by name. The LLM never sees passwords. `auth login` navigates with `load` and then waits for login form selectors to appear (SPA-friendly, timeout follows the default action timeout). A key is auto-generated at `~/.agent-browser/.encryption-key` if `AGENT_BROWSER_ENCRYPTION_KEY` is not set: `echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin` then `agent-browser auth login github` -- **Plugin System**: Extend agent-browser with external executable plugins. Plugins run out-of-process over the `agent-browser.plugin.v1` stdio JSON protocol and declare capabilities such as `credential.read`, `browser.provider`, `launch.mutate`, or `command.run`. -- **Content Boundary Markers**: Wrap page output in delimiters so LLMs can distinguish tool output from untrusted content: `--content-boundaries` -- **Domain Allowlist**: Restrict navigation to trusted domains (wildcards like `*.example.com` also match the bare domain): `--allowed-domains "example.com,*.example.com"`. Sub-resource requests (scripts, images, fetch) and WebSocket/EventSource connections to non-allowed domains are also blocked. Include any CDN domains your target pages depend on (e.g., `*.cdn.example.com`). -- **Action Policy**: Gate destructive actions with a static policy file: `--action-policy ./policy.json` -- **Action Confirmation**: Require explicit approval for sensitive action categories: `--confirm-actions eval,download` -- **Output Length Limits**: Prevent context flooding: `--max-output 50000` +- **Authentication Vault(身份验证保险库)**:在本地存储凭据(始终加密),按名称引用。LLM 永远不会看到密码。`auth login` 使用 `load` 导航,然后等待登录表单选择器出现(适配 SPA,超时遵循默认操作超时)。若未设置 `AGENT_BROWSER_ENCRYPTION_KEY`,会在 `~/.agent-browser/.encryption-key` 自动生成密钥:`echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin`,然后 `agent-browser auth login github` +- **Plugin System(插件系统)**:通过外部可执行插件扩展 agent-browser。插件通过 `agent-browser.plugin.v1` stdio JSON 协议在进程外运行,并声明 `credential.read`、`browser.provider`、`launch.mutate` 或 `command.run` 等能力。 +- **Content Boundary Markers(内容边界标记)**:用分隔符包裹页面输出,使 LLM 能区分工具输出与不受信任的内容:`--content-boundaries` +- **Domain Allowlist(域名允许列表)**:将导航限制在受信任域名(通配符如 `*.example.com` 也会匹配裸域名):`--allowed-domains "example.com,*.example.com"`。对非允许域名的子资源请求(脚本、图片、fetch)以及 WebSocket/EventSource 连接也会被阻止。请包含目标页面所依赖的任何 CDN 域名(例如 `*.cdn.example.com`)。 +- **Action Policy(操作策略)**:通过静态策略文件管控破坏性操作:`--action-policy ./policy.json` +- **Action Confirmation(操作确认)**:对敏感操作类别要求显式批准:`--confirm-actions eval,download` +- **Output Length Limits(输出长度限制)**:防止上下文泛滥:`--max-output 50000` -| Variable | Description | +| 变量 | 说明 | | ----------------------------------- | ---------------------------------------- | -| `AGENT_BROWSER_CONTENT_BOUNDARIES` | Wrap page output in boundary markers | -| `AGENT_BROWSER_MAX_OUTPUT` | Max characters for page output | -| `AGENT_BROWSER_ALLOWED_DOMAINS` | Comma-separated allowed domain patterns | -| `AGENT_BROWSER_ACTION_POLICY` | Path to action policy JSON file | -| `AGENT_BROWSER_CONFIRM_ACTIONS` | Action categories requiring confirmation | -| `AGENT_BROWSER_CONFIRM_INTERACTIVE` | Enable interactive confirmation prompts | -| `AGENT_BROWSER_PLUGINS` | JSON plugin registry override | +| `AGENT_BROWSER_CONTENT_BOUNDARIES` | 在页面输出外包装边界标记 | +| `AGENT_BROWSER_MAX_OUTPUT` | 页面输出的最大字符数 | +| `AGENT_BROWSER_ALLOWED_DOMAINS` | 逗号分隔的允许域名模式 | +| `AGENT_BROWSER_ACTION_POLICY` | 操作策略 JSON 文件路径 | +| `AGENT_BROWSER_CONFIRM_ACTIONS` | 需要确认的操作类别 | +| `AGENT_BROWSER_CONFIRM_INTERACTIVE` | 启用交互式确认提示 | +| `AGENT_BROWSER_PLUGINS` | JSON 插件注册表覆盖 | -See [Security documentation](https://agent-browser.dev/security) for details. +详见[安全文档](https://agent-browser.dev/security) 了解详情。 -### Plugin System +### 插件系统 -Plugins let third-party tools integrate without becoming built-in agent-browser dependencies. Add a plugin from npm or GitHub: +插件允许第三方工具集成,而无需成为 agent-browser 的内置依赖。从 npm 或 GitHub 添加插件: ```bash agent-browser plugin add agent-browser-plugin-captcha @@ -747,11 +753,11 @@ agent-browser plugin add @company/agent-browser-plugin-vault --name vault agent-browser plugin add org/agent-browser-plugin-cloud-browser ``` -References are resolved by shape: `name` uses npm, `@scope/name` uses npm, and `owner/repo` uses GitHub. `plugin add` writes `./agent-browser.json` by default; use `--global` for `~/.agent-browser/config.json`. +引用按形态解析:`name` 使用 npm,`@scope/name` 使用 npm,`owner/repo` 使用 GitHub。`plugin add` 默认写入 `./agent-browser.json`;对 `~/.agent-browser/config.json` 使用 `--global`。 -Plugin packages should support `plugin.manifest` so `plugin add` can discover their name and capabilities automatically. If a plugin does not support manifests, pass `--capability ` during add. +插件包应支持 `plugin.manifest`,以便 `plugin add` 能自动发现其名称和功能。若插件不支持清单(manifest),在添加时传入 `--capability `。 -Plugins can also be configured manually in `agent-browser.json`: +也可以在 `agent-browser.json` 中手动配置插件: ```json { @@ -780,41 +786,41 @@ Plugins can also be configured manually in `agent-browser.json`: } ``` -Inspect configured plugins: +检查已配置的插件: ```bash agent-browser plugin list agent-browser plugin show vault ``` -Use a credential provider plugin for one login: +使用凭据提供方(credential provider)插件进行单次登录: ```bash agent-browser auth login my-app --credential-provider vault --item "My App" agent-browser auth login my-app --credential-provider vault --item "My App" --url https://app.example.com/login --username-selector "#email" --password-selector "#password" --submit-selector "button[type=submit]" ``` -Use a browser provider plugin: +使用浏览器提供方(browser provider)插件: ```bash agent-browser --provider cloud-browser open https://example.com ``` -Use a launch mutator plugin for stealth or local launch customization. The plugin can append Chrome args, extensions, and init scripts before the browser starts: +使用启动变更(launch mutator)插件实现隐身或本地启动自定义。浏览器启动前,插件可追加 Chrome 参数、扩展和初始化脚本: ```bash agent-browser open https://example.com ``` -Use a generic plugin command for domain-specific tools such as CAPTCHA solvers: +对 CAPTCHA 求解器等特定领域工具,使用通用插件命令: ```bash agent-browser plugin run captcha captcha.solve --payload '{"siteKey":"...","url":"https://example.com"}' ``` -The protocol request always includes `protocol`, `type`, `capability`, and `request`. A credential plugin receives `credential.resolve`, a browser provider receives `browser.launch`, a launch mutator receives `launch.mutate`, and generic commands receive the supplied request type. `plugin run` is for `command.run` and custom capabilities; core capabilities and protocol request types use their dedicated command paths. agent-browser keeps browser automation, redaction-sensitive output, and policy enforcement in core. +协议请求始终包含 `protocol`、`type`、`capability` 和 `request`。凭据插件接收 `credential.resolve`,浏览器提供方接收 `browser.launch`,启动变更器接收 `launch.mutate`,通用命令接收所提供的请求类型。`plugin run` 用于 `command.run` 及自定义能力;核心能力和协议请求类型使用其专用命令路径。agent-browser 将浏览器自动化、脱敏敏感输出和策略强制执行保留在核心中。 -Gate plugin access by capability action: +按能力操作限制插件访问: ```bash agent-browser --confirm-actions plugin:vault:credential.read auth login my-app --credential-provider vault --item "My App" @@ -822,11 +828,11 @@ agent-browser --confirm-actions plugin:cloud-browser:browser.provider --provider agent-browser --confirm-actions plugin:stealth:launch.mutate open https://example.com ``` -Do not put vault tokens or passwords in plugin command args. Use the vault vendor's own login/session mechanism or environment outside agent-browser config. +不要在插件命令参数中放置保管库(vault)令牌或密码。请使用保管库供应商自身的登录/会话机制,或在 agent-browser 配置之外的环境变量中配置。 -## Snapshot Options +## 快照选项 -The `snapshot` command supports filtering to reduce output size: +`snapshot` 命令支持过滤以减小输出体积: ```bash agent-browser snapshot # Full accessibility tree @@ -838,19 +844,19 @@ agent-browser snapshot -s "#main" # Scope to CSS selector agent-browser snapshot -i -c -d 5 # Combine options ``` -| Option | Description | +| 选项 | 说明 | | ---------------------- | ----------------------------------------------------------------------- | -| `-i, --interactive` | Only show interactive elements (buttons, links, inputs) | -| `-u, --urls` | Include href URLs for link elements | -| `-c, --compact` | Remove empty structural elements | -| `-d, --depth ` | Limit tree depth | -| `-s, --selector ` | Scope to CSS selector | +| `-i, --interactive` | 仅显示交互元素(按钮、链接、输入框) | +| `-u, --urls` | 为链接元素包含 href URL | +| `-c, --compact` | 移除空的结构元素 | +| `-d, --depth ` | 限制树深度 | +| `-s, --selector ` | 限定为 CSS 选择器范围 | -## Annotated Screenshots +## 标注截图 -The `--annotate` flag overlays numbered labels on interactive elements in the screenshot. Each label `[N]` corresponds to ref `@eN`, so the same refs work for both visual and text-based workflows. +`--annotate` 标志会在截图中的交互元素上叠加编号标签。每个标签 `[N]` 对应 ref `@eN`,因此同一套 ref 可同时用于视觉工作流和基于文本的工作流。 -Annotated screenshots are supported on the CDP-backed browser path (Chrome/Lightpanda). The Safari/WebDriver backend does not yet support `--annotate`. +基于 CDP(Chrome DevTools Protocol)的浏览器路径(Chrome/Lightpanda)支持标注截图。Safari/WebDriver 后端尚不支持 `--annotate`。 ```bash agent-browser screenshot --annotate @@ -860,70 +866,70 @@ agent-browser screenshot --annotate # [3] @e3 textbox "Email" ``` -After an annotated screenshot, refs are cached so you can immediately interact with elements: +标注截图后,ref 会被缓存,便于立即与元素交互: ```bash agent-browser screenshot --annotate ./page.png agent-browser click @e2 # Click the "Home" link labeled [2] ``` -This is useful for multimodal AI models that can reason about visual layout, unlabeled icon buttons, canvas elements, or visual state that the text accessibility tree cannot capture. +这对能够推理视觉布局、无文字图标按钮、canvas 元素或文本无障碍树无法捕获的视觉状态的多模态 AI 模型很有用。 -## Options +## 选项 -| Option | Description | +| 选项 | 说明 | |--------|-------------| -| `--session ` | Use isolated session (or `AGENT_BROWSER_SESSION` env) | -| `--restore [name]` | Auto-save/restore session state. Bare `--restore` uses `--session` as the key | -| `--restore-save ` | Restore save policy: `auto`, `always`, or `never` | -| `--restore-check-url ` | Validate restored state against a URL pattern | -| `--restore-check-text ` | Validate restored state against page text | -| `--restore-check-fn ` | Validate restored state against a truthy JavaScript expression | -| `--namespace ` | Isolate daemon sockets and restore-state directories | -| `--session-name ` | Legacy alias for restore persistence key | -| `--profile ` | Chrome profile name or persistent directory path (or `AGENT_BROWSER_PROFILE` env) | -| `--state ` | Load storage state from JSON file (or `AGENT_BROWSER_STATE` env) | -| `--headers ` | Set HTTP headers scoped to the URL's origin | -| `--executable-path ` | Custom browser executable (or `AGENT_BROWSER_EXECUTABLE_PATH` env) | -| `--extension ` | Load browser extension (repeatable; or `AGENT_BROWSER_EXTENSIONS` env) | -| `--init-script ` | Register a page init script before the first navigation (repeatable; or `AGENT_BROWSER_INIT_SCRIPTS` env) | -| `--enable ` | Built-in init scripts: `react-devtools` (repeatable or comma-list; or `AGENT_BROWSER_ENABLE` env) | -| `--args ` | Browser launch args, comma or newline separated (or `AGENT_BROWSER_ARGS` env) | -| `--user-agent ` | Custom User-Agent string (or `AGENT_BROWSER_USER_AGENT` env) | -| `--proxy ` | Proxy server URL with optional auth (or `AGENT_BROWSER_PROXY` env) | -| `--proxy-bypass ` | Hosts to bypass proxy (or `AGENT_BROWSER_PROXY_BYPASS` env) | -| `--ignore-https-errors` | Ignore HTTPS certificate errors (useful for self-signed certs) | -| `--allow-file-access` | Allow file:// URLs to access local files (Chromium only) | -| `--hide-scrollbars ` | Hide native scrollbars in headless Chromium screenshots, enabled by default (or `AGENT_BROWSER_HIDE_SCROLLBARS` env) | -| `-p, --provider ` | Browser provider, including configured `browser.provider` plugins (or `AGENT_BROWSER_PROVIDER` env) | -| `--device ` | iOS device name, e.g. "iPhone 15 Pro" (or `AGENT_BROWSER_IOS_DEVICE` env) | -| `--json` | JSON output (for agents) | -| `--annotate` | Annotated screenshot with numbered element labels (or `AGENT_BROWSER_ANNOTATE` env) | -| `--screenshot-dir ` | Default screenshot output directory (or `AGENT_BROWSER_SCREENSHOT_DIR` env) | -| `--screenshot-quality ` | JPEG quality 0-100 (or `AGENT_BROWSER_SCREENSHOT_QUALITY` env) | -| `--screenshot-format ` | Screenshot format: `png`, `jpeg` (or `AGENT_BROWSER_SCREENSHOT_FORMAT` env) | -| `--headed` | Show browser window (not headless) (or `AGENT_BROWSER_HEADED` env) | -| `--cdp ` | Connect via Chrome DevTools Protocol (port or WebSocket URL) | -| `--auto-connect` | Auto-discover and connect to running Chrome (or `AGENT_BROWSER_AUTO_CONNECT` env) | -| `--color-scheme ` | Color scheme: `dark`, `light`, `no-preference` (or `AGENT_BROWSER_COLOR_SCHEME` env) | -| `--download-path ` | Default download directory (or `AGENT_BROWSER_DOWNLOAD_PATH` env) | -| `--content-boundaries` | Wrap page output in boundary markers for LLM safety (or `AGENT_BROWSER_CONTENT_BOUNDARIES` env) | -| `--max-output ` | Truncate page output to N characters (or `AGENT_BROWSER_MAX_OUTPUT` env) | -| `--allowed-domains ` | Comma-separated allowed domain patterns (or `AGENT_BROWSER_ALLOWED_DOMAINS` env) | -| `--action-policy ` | Path to action policy JSON file (or `AGENT_BROWSER_ACTION_POLICY` env) | -| `--confirm-actions ` | Action categories requiring confirmation (or `AGENT_BROWSER_CONFIRM_ACTIONS` env) | -| `--confirm-interactive` | Interactive confirmation prompts; auto-denies if stdin is not a TTY (or `AGENT_BROWSER_CONFIRM_INTERACTIVE` env) | -| `--engine ` | Browser engine: `chrome` (default), `lightpanda` (or `AGENT_BROWSER_ENGINE` env) | -| `--no-auto-dialog` | Disable automatic dismissal of `alert`/`beforeunload` dialogs (or `AGENT_BROWSER_NO_AUTO_DIALOG` env) | -| `--model ` | AI model for chat command (or `AI_GATEWAY_MODEL` env) | -| `-v`, `--verbose` | Show tool commands and their raw output (chat) | -| `-q`, `--quiet` | Show only AI text responses, hide tool calls (chat) | -| `--config ` | Use a custom config file (or `AGENT_BROWSER_CONFIG` env) | -| `--debug` | Debug output | +| `--session ` | 使用隔离会话(或 `AGENT_BROWSER_SESSION` 环境变量) | +| `--restore [name]` | 自动保存/恢复会话状态。单独的 `--restore` 以 `--session` 作为键 | +| `--restore-save ` | 恢复保存策略:`auto`、`always` 或 `never` | +| `--restore-check-url ` | 根据 URL 模式验证恢复的状态 | +| `--restore-check-text ` | 根据页面文本验证恢复的状态 | +| `--restore-check-fn ` | 根据为真的 JavaScript 表达式验证恢复的状态 | +| `--namespace ` | 隔离守护进程套接字和恢复状态目录 | +| `--session-name ` | 恢复持久化键的旧版别名 | +| `--profile ` | Chrome 配置文件名称或持久目录路径(或 `AGENT_BROWSER_PROFILE` 环境变量) | +| `--state ` | 从 JSON 文件加载存储状态(或 `AGENT_BROWSER_STATE` 环境变量) | +| `--headers ` | 设置限定于 URL 源(origin)的 HTTP 标头 | +| `--executable-path ` | 自定义浏览器可执行文件(或 `AGENT_BROWSER_EXECUTABLE_PATH` 环境变量) | +| `--extension ` | 加载浏览器扩展(可重复;或 `AGENT_BROWSER_EXTENSIONS` 环境变量) | +| `--init-script ` | 在首次导航前注册页面初始化脚本(可重复;或 `AGENT_BROWSER_INIT_SCRIPTS` 环境变量) | +| `--enable ` | 内置初始化脚本:`react-devtools`(可重复或逗号分隔列表;或 `AGENT_BROWSER_ENABLE` 环境变量) | +| `--args ` | 浏览器启动参数,逗号或换行分隔(或 `AGENT_BROWSER_ARGS` 环境变量) | +| `--user-agent ` | 自定义 User-Agent 字符串(或 `AGENT_BROWSER_USER_AGENT` 环境变量) | +| `--proxy ` | 代理服务器 URL,可选身份验证(或 `AGENT_BROWSER_PROXY` 环境变量) | +| `--proxy-bypass ` | 绕过代理的主机(或 `AGENT_BROWSER_PROXY_BYPASS` 环境变量) | +| `--ignore-https-errors` | 忽略 HTTPS 证书错误(适用于自签名证书) | +| `--allow-file-access` | 允许 file:// URL 访问本地文件(仅 Chromium) | +| `--hide-scrollbars ` | 在无头 Chromium 截图中隐藏原生滚动条,默认启用(或 `AGENT_BROWSER_HIDE_SCROLLBARS` 环境变量) | +| `-p, --provider ` | 浏览器提供方,包括已配置的 `browser.provider` 插件(或 `AGENT_BROWSER_PROVIDER` 环境变量) | +| `--device ` | iOS 设备名称,例如 "iPhone 15 Pro"(或 `AGENT_BROWSER_IOS_DEVICE` 环境变量) | +| `--json` | JSON 输出(供 agent 使用) | +| `--annotate` | 带编号元素标签的标注截图(或 `AGENT_BROWSER_ANNOTATE` 环境变量) | +| `--screenshot-dir ` | 默认截图输出目录(或 `AGENT_BROWSER_SCREENSHOT_DIR` 环境变量) | +| `--screenshot-quality ` | JPEG 质量 0-100(或 `AGENT_BROWSER_SCREENSHOT_QUALITY` 环境变量) | +| `--screenshot-format ` | 截图格式:`png`、`jpeg`(或 `AGENT_BROWSER_SCREENSHOT_FORMAT` 环境变量) | +| `--headed` | 显示浏览器窗口(非无头模式)(或 `AGENT_BROWSER_HEADED` 环境变量) | +| `--cdp ` | 通过 Chrome DevTools Protocol(CDP)连接(端口或 WebSocket URL) | +| `--auto-connect` | 自动发现并连接正在运行的 Chrome(或 `AGENT_BROWSER_AUTO_CONNECT` 环境变量) | +| `--color-scheme ` | 配色方案:`dark`、`light`、`no-preference`(或 `AGENT_BROWSER_COLOR_SCHEME` 环境变量) | +| `--download-path ` | 默认下载目录(或 `AGENT_BROWSER_DOWNLOAD_PATH` 环境变量) | +| `--content-boundaries` | 为 LLM 安全在页面输出外包装边界标记(或 `AGENT_BROWSER_CONTENT_BOUNDARIES` 环境变量) | +| `--max-output ` | 将页面输出截断至 N 个字符(或 `AGENT_BROWSER_MAX_OUTPUT` 环境变量) | +| `--allowed-domains ` | 逗号分隔的允许域名模式(或 `AGENT_BROWSER_ALLOWED_DOMAINS` 环境变量) | +| `--action-policy ` | 操作策略 JSON 文件路径(或 `AGENT_BROWSER_ACTION_POLICY` 环境变量) | +| `--confirm-actions ` | 需要确认的操作类别(或 `AGENT_BROWSER_CONFIRM_ACTIONS` 环境变量) | +| `--confirm-interactive` | 交互式确认提示;若 stdin 不是 TTY 则自动拒绝(或 `AGENT_BROWSER_CONFIRM_INTERACTIVE` 环境变量) | +| `--engine ` | 浏览器引擎:`chrome`(默认)、`lightpanda`(或 `AGENT_BROWSER_ENGINE` 环境变量) | +| `--no-auto-dialog` | 禁用 `alert`/`beforeunload` 对话框的自动关闭(或 `AGENT_BROWSER_NO_AUTO_DIALOG` 环境变量) | +| `--model ` | 聊天命令使用的 AI 模型(或 `AI_GATEWAY_MODEL` 环境变量) | +| `-v`, `--verbose` | 显示工具命令及其原始输出(聊天) | +| `-q`, `--quiet` | 仅显示 AI 文本回复,隐藏工具调用(聊天) | +| `--config ` | 使用自定义配置文件(或 `AGENT_BROWSER_CONFIG` 环境变量) | +| `--debug` | 调试输出 | -## Observability Dashboard +## 可观测性仪表板(Observability Dashboard) -Monitor agent-browser sessions in real time with a local web dashboard showing a live viewport and command activity feed. +通过本地 Web 仪表板实时监控 agent-browser 会话,展示实时视口和命令活动流。 ```bash # Start the dashboard server (runs in background on port 4848) @@ -937,18 +943,18 @@ agent-browser open example.com agent-browser dashboard stop ``` -The dashboard runs as a standalone background process on port 4848, independent of browser sessions. It stays available even when no sessions are running, and it works from `http://localhost:4848` or a proxied/forwarded URL that reaches the dashboard server, such as `https://dashboard.agent-browser.localhost` or a Coder workspace URL. The browser stays on the dashboard origin; session-specific tabs, status, and stream traffic are proxied internally, so session ports do not need to be exposed. +仪表板在 4848 端口作为独立后台进程运行,与浏览器会话无关。即使没有会话在运行,它仍保持可用,并且可从 `http://localhost:4848` 或能访问仪表板服务器的代理/转发 URL(例如 `https://dashboard.agent-browser.localhost` 或 Coder 工作区 URL)使用。浏览器始终停留在仪表板源站;会话专属的标签页、状态和流式流量在内部被代理,因此无需暴露会话端口。 -The dashboard displays: -- **Live viewport**: real-time JPEG frames from the browser -- **Activity feed**: chronological command/result stream with timing and expandable details -- **Console output**: browser console messages (log, warn, error) -- **Session creation**: create new sessions from the UI with local engines (Chrome, Lightpanda) or cloud providers (AgentCore, Browserbase, Browserless, Browser Use, Kernel) -- **AI Chat**: chat with an AI assistant directly in the dashboard (requires Vercel AI Gateway configuration) +仪表板展示: +- **实时视口**:来自浏览器的实时 JPEG 帧 +- **活动流**:按时间顺序排列的命令/结果流,含耗时和可展开的详情 +- **控制台输出**:浏览器控制台消息(log、warn、error) +- **会话创建**:通过 UI 使用本地引擎(Chrome、Lightpanda)或云提供商(AgentCore、Browserbase、Browserless、Browser Use、Kernel)创建新会话 +- **AI 聊天**:在仪表板中直接与 AI 助手对话(需配置 Vercel AI Gateway) -### AI Chat +### AI 聊天 -The dashboard includes an optional AI chat panel powered by the Vercel AI Gateway. The same functionality is available directly from the CLI via the `chat` command. Set these environment variables to enable AI chat: +仪表板包含由 Vercel AI Gateway 驱动的可选 AI 聊天面板。相同功能也可通过 CLI 的 `chat` 命令直接使用。设置以下环境变量以启用 AI 聊天: ```bash export AI_GATEWAY_API_KEY=gw_your_key_here @@ -956,7 +962,7 @@ export AI_GATEWAY_MODEL=anthropic/claude-sonnet-4.6 # optional, this i export AI_GATEWAY_URL=https://ai-gateway.vercel.sh # optional, this is the default ``` -**CLI usage:** +**CLI 用法:** ```bash agent-browser chat "open google.com and search for cats" # Single-shot @@ -966,24 +972,24 @@ agent-browser -v chat "fill in the login form" # Verbose (show com agent-browser --model openai/gpt-4o chat "take a screenshot" # Override model ``` -The `chat` command translates natural language instructions into agent-browser commands, executes them, and streams the AI response. In interactive mode, type `quit` to exit. Use `--json` for structured output suitable for agent consumption. +`chat` 命令将自然语言指令转换为 agent-browser 命令、执行它们并流式传输 AI 响应。在交互模式下,输入 `quit` 退出。使用 `--json` 获取适合代理消费的结构化输出。 -**Dashboard usage:** +**仪表板用法:** -The Chat tab is always visible in the dashboard. When `AI_GATEWAY_API_KEY` is set, the Rust server proxies requests to the gateway and streams responses back using the Vercel AI SDK's UI Message Stream protocol. Without the key, sending a message shows an error inline. +聊天选项卡在仪表板中始终可见。当设置 `AI_GATEWAY_API_KEY` 时,Rust 服务器将请求代理到网关,并使用 Vercel AI SDK 的 UI Message Stream 协议流式返回响应。未设置密钥时,发送消息会在界面内显示错误。 -## Configuration +## 配置 -Create an `agent-browser.json` file to set persistent defaults instead of repeating flags on every command. +创建 `agent-browser.json` 文件以设置持久默认值,避免在每条命令上重复指定标志。 -**Locations (lowest to highest priority):** +**位置(优先级从低到高):** -1. `~/.agent-browser/config.json`: user-level defaults -2. `./agent-browser.json`: project-level overrides (in working directory) -3. `AGENT_BROWSER_*` environment variables override config file values -4. CLI flags override everything +1. `~/.agent-browser/config.json`:用户级默认值 +2. `./agent-browser.json`:项目级覆盖(在工作目录中) +3. `AGENT_BROWSER_*` 环境变量覆盖配置文件值 +4. CLI 标志覆盖一切 -**Example `agent-browser.json`:** +**`agent-browser.json` 示例:** ```json { @@ -1003,16 +1009,16 @@ Create an `agent-browser.json` file to set persistent defaults instead of repeat } ``` -Use `--config ` or `AGENT_BROWSER_CONFIG` to load a specific config file instead of the defaults: +使用 `--config ` 或 `AGENT_BROWSER_CONFIG` 加载特定配置文件,而非默认配置: ```bash agent-browser --config ./ci-config.json open example.com AGENT_BROWSER_CONFIG=./ci-config.json agent-browser open example.com ``` -All options from the table above can be set in the config file using camelCase keys (e.g., `--executable-path` becomes `"executablePath"`, `--proxy-bypass` becomes `"proxyBypass"`). Plugins are configured with the `"plugins"` array shown above. Unknown keys are ignored for forward compatibility. +上表中的所有选项均可在配置文件中使用 camelCase 键设置(例如,`--executable-path` 变为 `"executablePath"`,`--proxy-bypass` 变为 `"proxyBypass"`)。插件通过上文所示的 `"plugins"` 数组配置。为向前兼容,未知键会被忽略。 -A [JSON Schema](agent-browser.schema.json) is available for IDE autocomplete and validation. Add a `$schema` key to your config file to enable it: +提供 [JSON Schema](agent-browser.schema.json) 供 IDE 自动补全和校验。在配置文件中添加 `$schema` 键以启用: ```json { @@ -1021,34 +1027,34 @@ A [JSON Schema](agent-browser.schema.json) is available for IDE autocomplete and } ``` -Boolean flags accept an optional `true`/`false` value to override config settings. For example, `--headed false` disables `"headed": true` from config. A bare `--headed` is equivalent to `--headed true`. +布尔标志可接受可选的 `true`/`false` 值以覆盖配置设置。例如,`--headed false` 会禁用配置文件中的 `"headed": true`。单独的 `--headed` 等同于 `--headed true`。 -Auto-discovered config files that are missing are silently ignored. If `--config ` points to a missing or invalid file, agent-browser exits with an error. Extensions from user and project configs are merged (concatenated), not replaced. +自动发现的缺失配置文件会被静默忽略。若 `--config ` 指向缺失或无效文件,agent-browser 会以错误退出。用户级与项目级配置中的扩展会合并(拼接),而非替换。 -> **Tip:** If your project-level `agent-browser.json` contains environment-specific values (paths, proxies), consider adding it to `.gitignore`. +> **提示:** 若项目级 `agent-browser.json` 包含环境相关值(路径、代理等),建议将其加入 `.gitignore`。 -## Default Timeout +## 默认超时 -The default timeout for standard operations (clicks, waits, fills, etc.) is 25 seconds. This is intentionally below the CLI's 30-second IPC read timeout so that the daemon returns a proper error instead of the CLI timing out with EAGAIN. +标准操作(点击、等待、填充等)的默认超时为 25 秒。此值有意低于 CLI 的 30 秒 IPC 读取超时,以便守护进程返回正确错误,而非 CLI 因 EAGAIN 超时。 -Override the default timeout via environment variable: +通过环境变量覆盖默认超时: ```bash # Set a longer timeout for slow pages (in milliseconds) export AGENT_BROWSER_DEFAULT_TIMEOUT=45000 ``` -> **Note:** Setting this above 30000 (30s) may cause EAGAIN errors on slow operations because the CLI's read timeout will expire before the daemon responds. The CLI retries transient errors automatically, but response times will increase. +> **注意:** 将此值设为超过 30000(30 秒)可能导致慢操作出现 EAGAIN 错误,因为 CLI 的读取超时会在守护进程响应前过期。CLI 会自动重试瞬时错误,但响应时间会增加。 -| Variable | Description | +| 变量 | 说明 | | ------------------------------- | ---------------------------------------- | -| `AGENT_BROWSER_DEFAULT_TIMEOUT` | Default operation timeout in ms (default: 25000) | +| `AGENT_BROWSER_DEFAULT_TIMEOUT` | 默认操作超时(毫秒,默认:25000) | -## Selectors +## 选择器 -### Refs (Recommended for AI) +### Refs(推荐用于 AI) -Refs provide deterministic element selection from snapshots: +Refs 从快照提供确定性的元素选择: ```bash # 1. Get snapshot with refs @@ -1066,15 +1072,15 @@ agent-browser get text @e1 # Get heading text agent-browser hover @e4 # Hover the link ``` -When a ref click is blocked by an overlay, the error includes the covering element, such as `covered by `. Click the banner or dialog control first, then run `snapshot` again before reusing refs. +当 ref 点击被遮罩层阻挡时,错误信息会包含遮盖元素,例如 `covered by `。请先点击横幅或对话框控件,再重新运行 `snapshot`,然后方可复用 refs。 -**Why use refs?** +**为何使用 refs?** -- **Deterministic**: Ref points to exact element from snapshot -- **Fast**: No DOM re-query needed -- **AI-friendly**: Snapshot + ref workflow is optimal for LLMs +- **确定性**:Ref 指向快照中的精确元素 +- **快速**:无需重新查询 DOM +- **AI 友好**:快照 + ref 工作流最适合 LLM -### CSS Selectors +### CSS 选择器 ```bash agent-browser click "#id" @@ -1082,23 +1088,23 @@ agent-browser click ".class" agent-browser click "div > button" ``` -### Text & XPath +### 文本与 XPath ```bash agent-browser click "text=Submit" agent-browser click "xpath=//button" ``` -### Semantic Locators +### 语义定位器 ```bash agent-browser find role button click --name "Submit" agent-browser find label "Email" fill "test@test.com" ``` -## Agent Mode +## 代理模式 -Use `--json` for machine-readable output: +使用 `--json` 获取机器可读输出: ```bash agent-browser snapshot --json @@ -1108,7 +1114,7 @@ agent-browser get text @e1 --json agent-browser is visible @e2 --json ``` -### Optimal AI Workflow +### 最佳 AI 工作流 ```bash # 1. Navigate and get snapshot @@ -1124,9 +1130,9 @@ agent-browser fill @e3 "input text" agent-browser snapshot -i --json ``` -### Command Chaining +### 命令链 -Commands can be chained with `&&` in a single shell invocation. The browser persists via a background daemon, so chaining is safe and more efficient: +可在单次 shell 调用中使用 `&&` 将多条命令串联起来。浏览器通过后台守护进程保持运行,因此串联执行既安全又更高效: ```bash # Open, wait for load, and snapshot in one call @@ -1139,23 +1145,23 @@ agent-browser fill @e1 "user@example.com" && agent-browser fill @e2 "pass" && ag agent-browser open example.com && agent-browser wait --load networkidle && agent-browser screenshot page.png ``` -Use `&&` when you don't need intermediate output. Run commands separately when you need to parse output first (e.g., snapshot to discover refs before interacting). +当你不需要中间输出时,请使用 `&&`。若需要先解析输出(例如,先快照以发现引用再交互),请分别运行各条命令。 -## Headed Mode +## 有界面模式(Headed Mode) -Show the browser window for debugging: +显示浏览器窗口以便调试: ```bash agent-browser open example.com --headed ``` -This opens a visible browser window instead of running headless. +这将打开可见的浏览器窗口,而非以无头(headless)方式运行。 -> **Note:** Browser extensions work in both headed and headless mode (Chrome's `--headless=new`). +> **注意:** 浏览器扩展在有界面和无头模式下均可使用(Chrome 的 `--headless=new`)。 -## Authenticated Sessions +## 已认证会话 -Use `--headers` to set HTTP headers for a specific origin, enabling authentication without login flows: +使用 `--headers` 为特定源(origin)设置 HTTP 头,无需登录流程即可实现认证: ```bash # Headers are scoped to api.example.com only @@ -1169,35 +1175,35 @@ agent-browser click @e2 agent-browser open other-site.com ``` -This is useful for: +适用于: -- **Skipping login flows** - Authenticate via headers instead of UI -- **Switching users** - Start new sessions with different auth tokens -- **API testing** - Access protected endpoints directly -- **Security** - Headers are scoped to the origin, not leaked to other domains +- **跳过登录流程** - 通过请求头认证,而非 UI 登录 +- **切换用户** - 使用不同认证令牌启动新会话 +- **API 测试** - 直接访问受保护的端点 +- **安全性** - 请求头限定于该源,不会泄露到其他域名 -To set headers for multiple origins, use `--headers` with each `open` command: +要为多个源设置请求头,请在每条 `open` 命令中使用 `--headers`: ```bash agent-browser open api.example.com --headers '{"Authorization": "Bearer token1"}' agent-browser open api.acme.com --headers '{"Authorization": "Bearer token2"}' ``` -For global headers (all domains), use `set headers`: +对于全局请求头(所有域名),请使用 `set headers`: ```bash agent-browser set headers '{"X-Custom-Header": "value"}' ``` -## Custom Browser Executable +## 自定义浏览器可执行文件 -Use a custom browser executable instead of the bundled Chromium. This is useful for: +使用自定义浏览器可执行文件,而非捆绑的 Chromium。适用于: -- **Serverless deployment**: Use lightweight Chromium builds like `@sparticuz/chromium` (~50MB vs ~684MB) -- **System browsers**: Use an existing Chrome/Chromium installation -- **Custom builds**: Use modified browser builds +- **Serverless 部署**:使用轻量级 Chromium 构建,如 `@sparticuz/chromium`(约 50MB,对比约 684MB) +- **系统浏览器**:使用已有的 Chrome/Chromium 安装 +- **自定义构建**:使用修改过的浏览器构建 -### CLI Usage +### CLI 用法 ```bash # Via flag @@ -1207,9 +1213,9 @@ agent-browser --executable-path /path/to/chromium open example.com AGENT_BROWSER_EXECUTABLE_PATH=/path/to/chromium agent-browser open example.com ``` -### Serverless (Vercel) +### Serverless(Vercel) -Run agent-browser + Chrome in an ephemeral Vercel Sandbox microVM. No external server needed: +在临时的 Vercel Sandbox microVM 中运行 agent-browser 与 Chrome。无需外部服务器: ```typescript import { runAgentBrowserCommand, withAgentBrowserSandbox } from "@agent-browser/sandbox/vercel"; @@ -1220,11 +1226,11 @@ const result = await withAgentBrowserSandbox(async (sandbox) => { }); ``` -Install `@agent-browser/sandbox` and `@vercel/sandbox` in the consuming app. See the [sandbox helper example](examples/sandbox/) for minimal Eve and Vercel Sandbox usage, or the [environments example](examples/environments/) for a full UI demo with a deploy-to-Vercel button. +在消费端应用中安装 `@agent-browser/sandbox` 和 `@vercel/sandbox`。请参阅 [sandbox helper 示例](examples/sandbox/) 了解 Eve 与 Vercel Sandbox 的最小用法,或参阅 [environments 示例](examples/environments/) 查看带「部署到 Vercel」按钮的完整 UI 演示。 -Fresh Vercel and Eve sandboxes install Chromium system dependencies by default. Pass `installSystemDependencies: false` only when your sandbox image already includes those libraries. +全新的 Vercel 和 Eve 沙箱默认会安装 Chromium 系统依赖。仅当你的沙箱镜像已包含这些库时,才传入 `installSystemDependencies: false`。 -### Serverless (AWS Lambda) +### Serverless(AWS Lambda) ```typescript import chromium from '@sparticuz/chromium'; @@ -1240,9 +1246,9 @@ export async function handler() { } ``` -## Local Files +## 本地文件 -Open and interact with local files (PDFs, HTML, etc.) using `file://` URLs: +使用 `file://` URL 打开并操作本地文件(PDF、HTML 等): ```bash # Enable file access (required for JavaScript to access local files) @@ -1254,17 +1260,17 @@ agent-browser --allow-file-access open file:///Users/me/report.pdf agent-browser screenshot report.png ``` -The `--allow-file-access` flag adds Chromium flags (`--allow-file-access-from-files`, `--allow-file-access`) that allow `file://` URLs to: +`--allow-file-access` 标志会添加 Chromium 标志(`--allow-file-access-from-files`、`--allow-file-access`),使 `file://` URL 能够: -- Load and render local files -- Access other local files via JavaScript (XHR, fetch) -- Load local resources (images, scripts, stylesheets) +- 加载并渲染本地文件 +- 通过 JavaScript(XHR、fetch)访问其他本地文件 +- 加载本地资源(图片、脚本、样式表) -**Note:** This flag only works with Chromium. For security, it's disabled by default. +**注意:** 此标志仅适用于 Chromium。出于安全考虑,默认禁用。 -## CDP Mode +## CDP 模式 -Connect to an existing browser via Chrome DevTools Protocol: +通过 Chrome DevTools Protocol(CDP)连接到现有浏览器: ```bash # Start Chrome with: google-chrome --remote-debugging-port=9222 @@ -1282,21 +1288,21 @@ agent-browser --cdp 9222 snapshot agent-browser --cdp "wss://your-browser-service.com/cdp?token=..." snapshot ``` -The `--cdp` flag accepts either: +`--cdp` 标志可接受: -- A port number (e.g., `9222`) for local connections via `http://localhost:{port}` -- A full WebSocket URL (e.g., `wss://...` or `ws://...`) for remote browser services +- 端口号(例如 `9222`),用于通过 `http://localhost:{port}` 进行本地连接 +- 完整的 WebSocket URL(例如 `wss://...` 或 `ws://...`),用于远程浏览器服务 -This enables control of: +由此可控制: -- Electron apps -- Chrome/Chromium instances with remote debugging -- WebView2 applications -- Any browser exposing a CDP endpoint +- Electron 应用 +- 启用远程调试的 Chrome/Chromium 实例 +- WebView2 应用 +- 任何暴露 CDP 端点的浏览器 -### Auto-Connect +### 自动连接 -Use `--auto-connect` to automatically discover and connect to a running Chrome instance without specifying a port: +使用 `--auto-connect` 自动发现并连接到正在运行的 Chrome 实例,无需指定端口: ```bash # Auto-discover running Chrome with remote debugging @@ -1307,50 +1313,50 @@ agent-browser --auto-connect snapshot AGENT_BROWSER_AUTO_CONNECT=1 agent-browser snapshot ``` -Auto-connect discovers Chrome by: +自动连接通过以下方式发现 Chrome: -1. Reading Chrome's `DevToolsActivePort` file from the default user data directory -2. Falling back to probing common debugging ports (9222, 9229) -3. If HTTP-based discovery (`/json/version`, `/json/list`) fails, falling back to a direct WebSocket connection +1. 从默认用户数据目录读取 Chrome 的 `DevToolsActivePort` 文件 +2. 回退到探测常见调试端口(9222、9229) +3. 若基于 HTTP 的发现(`/json/version`、`/json/list`)失败,则回退到直接 WebSocket 连接 -This is useful when: +适用于: -- Chrome 144+ has remote debugging enabled via `chrome://inspect/#remote-debugging` (which uses a dynamic port) -- You want a zero-configuration connection to your existing browser -- You don't want to track which port Chrome is using +- Chrome 144+ 已通过 `chrome://inspect/#remote-debugging` 启用远程调试(使用动态端口) +- 你希望零配置连接到现有浏览器 +- 你不想跟踪 Chrome 正在使用的端口 -## Streaming (Browser Preview) +## 流式传输(浏览器预览) -Stream the browser viewport via WebSocket for live preview or "pair browsing" where a human can watch and interact alongside an AI agent. +通过 WebSocket 流式传输浏览器视口,用于实时预览或「结对浏览」(pair browsing),让人类可与 AI 智能体一同观看并交互。 -### Streaming +### 流式传输 -Every session automatically starts a WebSocket stream server on an OS-assigned port. Use `stream status` to see the bound port and connection state: +每个会话会自动在操作系统分配的端口上启动 WebSocket 流服务器。使用 `stream status` 查看绑定端口与连接状态: ```bash agent-browser stream status ``` -To bind to a specific port, set `AGENT_BROWSER_STREAM_PORT`: +要绑定到特定端口,请设置 `AGENT_BROWSER_STREAM_PORT`: ```bash AGENT_BROWSER_STREAM_PORT=9223 agent-browser open example.com ``` -You can also manage streaming at runtime with `stream enable`, `stream disable`, and `stream status`: +你也可以在运行时使用 `stream enable`、`stream disable` 和 `stream status` 管理流式传输: ```bash agent-browser stream enable --port 9223 # Re-enable on a specific port agent-browser stream disable # Stop streaming for the session ``` -The WebSocket server streams the browser viewport and accepts input events. +WebSocket 服务器会流式传输浏览器视口并接收输入事件。 -### WebSocket Protocol +### WebSocket 协议 -Connect to `ws://localhost:9223` to receive frames and send input: +连接到 `ws://localhost:9223` 以接收帧并发送输入: -**Receive frames:** +**接收帧:** ```json { @@ -1367,7 +1373,7 @@ Connect to `ws://localhost:9223` to receive frames and send input: } ``` -**Send mouse events:** +**发送鼠标事件:** ```json { @@ -1380,7 +1386,7 @@ Connect to `ws://localhost:9223` to receive frames and send input: } ``` -**Send keyboard events:** +**发送键盘事件:** ```json { @@ -1391,7 +1397,7 @@ Connect to `ws://localhost:9223` to receive frames and send input: } ``` -**Send touch events:** +**发送触摸事件:** ```json { @@ -1401,20 +1407,20 @@ Connect to `ws://localhost:9223` to receive frames and send input: } ``` -## Architecture +## 架构 -agent-browser uses a client-daemon architecture: +agent-browser 采用客户端-守护进程(client-daemon)架构: -1. **Rust CLI** - Parses commands, communicates with daemon -2. **Rust Daemon** - Pure Rust daemon using direct CDP, no Node.js required +1. **Rust CLI** - 解析命令,并与守护进程通信 +2. **Rust Daemon** - 纯 Rust 守护进程,直接使用 CDP,无需 Node.js -The daemon starts automatically on first command and persists between commands for fast subsequent operations. To auto-shutdown the daemon after a period of inactivity, set `AGENT_BROWSER_IDLE_TIMEOUT_MS` (value in milliseconds). When set, the daemon closes the browser and exits after receiving no commands for the specified duration. +守护进程会在首次执行命令时自动启动,并在命令之间保持运行,以便后续操作更快。若要在一段时间无活动后自动关闭守护进程,请设置 `AGENT_BROWSER_IDLE_TIMEOUT_MS`(值为毫秒)。设置后,若在所指定时长内未收到任何命令,守护进程将关闭浏览器并退出。 -**Browser Engine:** Uses Chrome (from Chrome for Testing) by default. The `--engine` flag selects between `chrome` and `lightpanda`. Supported browsers: Chromium/Chrome (via CDP) and Safari (via WebDriver for iOS). +**浏览器引擎:** 默认使用 Chrome(来自 Chrome for Testing)。`--engine` 标志可在 `chrome` 与 `lightpanda` 之间选择。支持的浏览器:Chromium/Chrome(通过 CDP)和 Safari(通过 WebDriver for iOS)。 -## Platforms +## 平台 -| Platform | Binary | +| 平台 | 二进制 | | ----------- | ----------- | | macOS ARM64 | Native Rust | | macOS x64 | Native Rust | @@ -1422,41 +1428,41 @@ The daemon starts automatically on first command and persists between commands f | Linux x64 | Native Rust | | Windows x64 | Native Rust | -## Usage with AI Agents +## 与 AI Agent 配合使用 -### Just ask the agent +### 直接让 Agent 使用 -The simplest approach is to tell your agent to use it: +最简单的方式是告诉你的 Agent 使用它: ``` Use agent-browser to test the login flow. Run agent-browser --help to see available commands. ``` -The `--help` output is comprehensive and most agents can figure it out from there. +`--help` 的输出内容很全面,大多数 Agent 都能据此自行掌握用法。 -### AI Coding Assistants (recommended) +### AI 编程助手(推荐) -Add the skill to your AI coding assistant for richer context: +将 skill 添加到你的 AI 编程助手中,以获得更丰富的上下文: ```bash npx skills add vercel-labs/agent-browser ``` -This works with Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Goose, OpenCode, and Windsurf. The skill is fetched from the repository, so it stays up to date automatically. Do not copy `SKILL.md` from `node_modules` as it will become stale. +适用于 Claude Code、Codex、Cursor、Gemini CLI、GitHub Copilot、Goose、OpenCode 和 Windsurf。该 skill 从仓库获取,因此会自动保持最新。请勿从 `node_modules` 复制 `SKILL.md`,否则内容会过时。 ### Claude Code -Install as a Claude Code skill: +安装为 Claude Code skill: ```bash npx skills add vercel-labs/agent-browser ``` -This adds a thin discovery stub at `.claude/skills/agent-browser/SKILL.md`. The stub is intentionally minimal — it points Claude Code at `agent-browser skills get core` to load the actual workflow content at runtime. This way the instructions always match the installed CLI version instead of going stale between releases. +这会在 `.claude/skills/agent-browser/SKILL.md` 添加一个轻量的发现桩(discovery stub)。该桩有意保持精简——它会在运行时引导 Claude Code 加载 `agent-browser skills get core` 中的实际工作流内容。这样,指令始终与已安装的 CLI 版本一致,而不会在版本发布之间过时。 ### AGENTS.md / CLAUDE.md -For more consistent results, add to your project or global instructions file: +为获得更稳定的结果,请添加到你的项目或全局指令文件中: ```markdown ## Browser Automation @@ -1471,13 +1477,13 @@ Core workflow: 4. Re-snapshot after page changes ``` -## Integrations +## 集成 -### iOS Simulator +### iOS 模拟器 -Control real Mobile Safari in the iOS Simulator for authentic mobile web testing. Requires macOS with Xcode. +在 iOS 模拟器中控制真实的 Mobile Safari,以进行真实的移动端 Web 测试。需要安装了 Xcode 的 macOS。 -**Setup:** +**设置:** ```bash # Install Appium and XCUITest driver @@ -1485,7 +1491,7 @@ npm install -g appium appium driver install xcuitest ``` -**Usage:** +**用法:** ```bash # List available iOS simulators @@ -1508,7 +1514,7 @@ agent-browser -p ios swipe down 500 agent-browser -p ios close ``` -Or use environment variables: +或使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=ios @@ -1516,21 +1522,21 @@ export AGENT_BROWSER_IOS_DEVICE="iPhone 16 Pro" agent-browser open https://example.com ``` -| Variable | Description | +| 变量 | 说明 | | -------------------------- | ----------------------------------------------- | -| `AGENT_BROWSER_PROVIDER` | Set to `ios` to enable iOS mode | -| `AGENT_BROWSER_IOS_DEVICE` | Device name (e.g., "iPhone 16 Pro", "iPad Pro") | -| `AGENT_BROWSER_IOS_UDID` | Device UDID (alternative to device name) | +| `AGENT_BROWSER_PROVIDER` | 设置为 `ios` 以启用 iOS 模式 | +| `AGENT_BROWSER_IOS_DEVICE` | 设备名称(例如 "iPhone 16 Pro"、"iPad Pro") | +| `AGENT_BROWSER_IOS_UDID` | 设备 UDID(可替代设备名称) | -**Supported devices:** All iOS Simulators available in Xcode (iPhones, iPads), plus real iOS devices. +**支持的设备:** Xcode 中所有可用的 iOS 模拟器(iPhone、iPad),以及真实 iOS 设备。 -**Note:** The iOS provider boots the simulator, starts Appium, and controls Safari. First launch takes ~30-60 seconds; subsequent commands are fast. +**注意:** iOS 提供程序会启动模拟器、启动 Appium 并控制 Safari。首次启动大约需要 30-60 秒;后续命令会很快。 -#### Real Device Support +#### 真机支持 -Appium also supports real iOS devices connected via USB. This requires additional one-time setup: +Appium 也支持通过 USB 连接的真实 iOS 设备。这需要额外的一次性设置: -**1. Get your device UDID:** +**1. 获取设备 UDID:** ```bash xcrun xctrace list devices @@ -1538,7 +1544,7 @@ xcrun xctrace list devices system_profiler SPUSBDataType | grep -A 5 "iPhone\|iPad" ``` -**2. Sign WebDriverAgent (one-time):** +**2. 签名 WebDriverAgent(一次性):** ```bash # Open the WebDriverAgent Xcode project @@ -1546,14 +1552,14 @@ cd ~/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriverag open WebDriverAgent.xcodeproj ``` -In Xcode: +在 Xcode 中: -- Select the `WebDriverAgentRunner` target -- Go to Signing & Capabilities -- Select your Team (requires Apple Developer account, free tier works) -- Let Xcode manage signing automatically +- 选择 `WebDriverAgentRunner` 目标 +- 前往 Signing & Capabilities +- 选择你的 Team(需要 Apple Developer 账户,免费套餐即可) +- 让 Xcode 自动管理签名 -**3. Use with agent-browser:** +**3. 与 agent-browser 配合使用:** ```bash # Connect device via USB, then: @@ -1563,25 +1569,25 @@ agent-browser -p ios --device "" open https://example.com agent-browser -p ios --device "John's iPhone" open https://example.com ``` -**Real device notes:** +**真机注意事项:** -- First run installs WebDriverAgent to the device (may require Trust prompt) -- Device must be unlocked and connected via USB -- Slightly slower initial connection than simulator -- Tests against real Safari performance and behavior +- 首次运行会将 WebDriverAgent 安装到设备上(可能需要信任提示) +- 设备必须已解锁并通过 USB 连接 +- 初始连接比模拟器稍慢 +- 可测试真实 Safari 的性能与行为 ### Browserless [Browserless](https://browserless.io) provides cloud browser infrastructure with a Sessions API. Use it when running agent-browser in environments where a local browser isn't available. -To enable Browserless, use the `-p` flag: +要启用 Browserless,请使用 `-p` 标志: ```bash export BROWSERLESS_API_KEY="your-api-token" agent-browser -p browserless open https://example.com ``` -Or use environment variables for CI/scripts: +或在 CI/脚本中使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=browserless @@ -1589,31 +1595,31 @@ export BROWSERLESS_API_KEY="your-api-token" agent-browser open https://example.com ``` -Optional configuration via environment variables: +可通过环境变量进行可选配置: -| Variable | Description | Default | +| 变量 | 说明 | 默认值 | | -------------------------- | ------------------------------------------------ | --------------------------------------- | -| `BROWSERLESS_API_URL` | Base API URL (for custom regions or self-hosted) | `https://production-sfo.browserless.io` | -| `BROWSERLESS_BROWSER_TYPE` | Type of browser to use (chromium or chrome) | chromium | -| `BROWSERLESS_TTL` | Session TTL in milliseconds | `300000` | -| `BROWSERLESS_STEALTH` | Enable stealth mode (`true`/`false`) | `true` | +| `BROWSERLESS_API_URL` | Base API URL(用于自定义区域或自托管) | `https://production-sfo.browserless.io` | +| `BROWSERLESS_BROWSER_TYPE` | 要使用的浏览器类型(chromium 或 chrome) | chromium | +| `BROWSERLESS_TTL` | 会话 TTL(毫秒) | `300000` | +| `BROWSERLESS_STEALTH` | 启用隐身模式(`true`/`false`) | `true` | -When enabled, agent-browser connects to a Browserless cloud session instead of launching a local browser. All commands work identically. +启用后,agent-browser 会连接到 Browserless 云会话,而不是启动本地浏览器。所有命令的行为完全相同。 -Get your API token from the [Browserless Dashboard](https://browserless.io). +从 [Browserless Dashboard](https://browserless.io). 获取你的 API 令牌 ### Browserbase [Browserbase](https://browserbase.com) provides remote browser infrastructure to make deployment of agentic browsing agents easy. Use it when running the agent-browser CLI in an environment where a local browser isn't feasible. -To enable Browserbase, use the `-p` flag: +要启用 Browserbase,请使用 `-p` 标志: ```bash export BROWSERBASE_API_KEY="your-api-key" agent-browser -p browserbase open https://example.com ``` -Or use environment variables for CI/scripts: +或在 CI/脚本中使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=browserbase @@ -1621,22 +1627,22 @@ export BROWSERBASE_API_KEY="your-api-key" agent-browser open https://example.com ``` -When enabled, agent-browser connects to a Browserbase session instead of launching a local browser. All commands work identically. +启用后,agent-browser 会连接到 Browserbase 会话,而不是启动本地浏览器。所有命令的行为完全相同。 -Get your API key from the [Browserbase Dashboard](https://browserbase.com/overview). +从 [Browserbase Dashboard](https://browserbase.com/overview). 获取你的 API 密钥 ### Browser Use [Browser Use](https://browser-use.com) provides cloud browser infrastructure for AI agents. Use it when running agent-browser in environments where a local browser isn't available (serverless, CI/CD, etc.). -To enable Browser Use, use the `-p` flag: +要启用 Browser Use,请使用 `-p` 标志: ```bash export BROWSER_USE_API_KEY="your-api-key" agent-browser -p browseruse open https://example.com ``` -Or use environment variables for CI/scripts: +或在 CI/脚本中使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=browseruse @@ -1644,22 +1650,22 @@ export BROWSER_USE_API_KEY="your-api-key" agent-browser open https://example.com ``` -When enabled, agent-browser connects to a Browser Use cloud session instead of launching a local browser. All commands work identically. +启用后,agent-browser 会连接到 Browser Use 云端会话,而不是启动本地浏览器。所有命令的行为保持一致。 -Get your API key from the [Browser Use Cloud Dashboard](https://cloud.browser-use.com/settings?tab=api-keys). Free credits are available to get started, with pay-as-you-go pricing after. +从 [Browser Use Cloud Dashboard](https://cloud.browser-use.com/settings?tab=api-keys). 获取 API 密钥。提供免费额度可供上手,之后按量计费。 ### Kernel -[Kernel](https://www.kernel.sh) provides cloud browser infrastructure for AI agents with features like stealth mode and persistent profiles. +[Kernel](https://www.kernel.sh) 为 AI 智能体提供云端浏览器基础设施,具备隐身模式(stealth mode)和持久化配置(persistent profiles)等功能。 -To enable Kernel, use the `-p` flag: +要启用 Kernel,请使用 `-p` 标志: ```bash export KERNEL_API_KEY="your-api-key" agent-browser -p kernel open https://example.com ``` -Or use environment variables for CI/scripts: +或在 CI/脚本中使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=kernel @@ -1667,54 +1673,54 @@ export KERNEL_API_KEY="your-api-key" agent-browser open https://example.com ``` -Optional configuration via environment variables: +可通过环境变量进行可选配置: -| Variable | Description | Default | +| 变量 | 说明 | 默认值 | | ------------------------ | -------------------------------------------------------------------------------- | ------- | -| `KERNEL_HEADLESS` | Run browser in headless mode (`true`/`false`) | `true` | -| `KERNEL_STEALTH` | Enable stealth mode to avoid bot detection (`true`/`false`) | `false` | -| `KERNEL_TIMEOUT_SECONDS` | Session timeout in seconds | `300` | -| `KERNEL_PROFILE_NAME` | Browser profile name for persistent cookies/logins (created if it doesn't exist) | (none) | +| `KERNEL_HEADLESS` | 以无头模式(headless)运行浏览器(`true`/`false`) | `true` | +| `KERNEL_STEALTH` | 启用隐身模式以避免机器人检测(`true`/`false`) | `false` | +| `KERNEL_TIMEOUT_SECONDS` | 会话超时时间(秒) | `300` | +| `KERNEL_PROFILE_NAME` | 用于持久化 Cookie/登录信息的浏览器配置名称(不存在时将自动创建) | (无) | -When enabled, agent-browser connects to a Kernel cloud session instead of launching a local browser. All commands work identically. +启用后,agent-browser 会连接到 Kernel 云端会话,而不是启动本地浏览器。所有命令的行为保持一致。 -**Profile Persistence:** When `KERNEL_PROFILE_NAME` is set, the profile will be created if it doesn't already exist. Cookies, logins, and session data are automatically saved back to the profile when the browser session ends, making them available for future sessions. +**配置持久化(Profile Persistence):** 设置 `KERNEL_PROFILE_NAME` 后,若该配置尚不存在,将自动创建。浏览器会话结束时,Cookie、登录信息和会话数据会自动保存回该配置,供后续会话使用。 -Get your API key from the [Kernel Dashboard](https://dashboard.onkernel.com). +从 [Kernel Dashboard](https://dashboard.onkernel.com). 获取 API 密钥。 ### AgentCore -[AWS Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/) provides cloud browser sessions with SigV4 authentication. +[AWS Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/) 提供带 SigV4 认证的云端浏览器会话。 -To enable AgentCore, use the `-p` flag: +要启用 AgentCore,请使用 `-p` 标志: ```bash agent-browser -p agentcore open https://example.com ``` -Or use environment variables for CI/scripts: +或在 CI/脚本中使用环境变量: ```bash export AGENT_BROWSER_PROVIDER=agentcore agent-browser open https://example.com ``` -Credentials are automatically resolved from environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) or the AWS CLI (`aws configure export-credentials`), which supports SSO, profiles, and IAM roles. +凭证会自动从环境变量(`AWS_ACCESS_KEY_ID`、`AWS_SECRET_ACCESS_KEY`)或 AWS CLI(`aws configure export-credentials`)解析,支持 SSO、配置文件和 IAM 角色。 -Optional configuration via environment variables: +可通过环境变量进行可选配置: -| Variable | Description | Default | +| 变量 | 说明 | 默认值 | | -------------------------- | -------------------------------------------------------------------- | ---------------- | -| `AGENTCORE_REGION` | AWS region for the AgentCore endpoint | `us-east-1` | -| `AGENTCORE_BROWSER_ID` | Browser identifier | `aws.browser.v1` | -| `AGENTCORE_PROFILE_ID` | Browser profile for persistent state (cookies, localStorage) | (none) | -| `AGENTCORE_SESSION_TIMEOUT`| Session timeout in seconds | `3600` | -| `AWS_PROFILE` | AWS CLI profile for credential resolution | `default` | +| `AGENTCORE_REGION` | AgentCore 端点的 AWS 区域 | `us-east-1` | +| `AGENTCORE_BROWSER_ID` | 浏览器标识符 | `aws.browser.v1` | +| `AGENTCORE_PROFILE_ID` | 用于持久化状态(cookies、localStorage)的浏览器配置 | (无) | +| `AGENTCORE_SESSION_TIMEOUT`| 会话超时时间(秒) | `3600` | +| `AWS_PROFILE` | 用于解析凭证的 AWS CLI 配置文件 | `default` | -**Browser profiles:** When `AGENTCORE_PROFILE_ID` is set, browser state (cookies, localStorage) is persisted across sessions automatically. +**浏览器配置(Browser profiles):** 设置 `AGENTCORE_PROFILE_ID` 后,浏览器状态(cookies、localStorage)会在各会话间自动持久化。 -When enabled, agent-browser connects to an AgentCore cloud browser session instead of launching a local browser. All commands work identically. +启用后,agent-browser 会连接到 AgentCore 云端浏览器会话,而不是启动本地浏览器。所有命令的行为保持一致。 -## License +## 许可证 Apache-2.0