商业产业 Hacker News AI 2026-08-02T06:15 正文 ok 399 words

Agent-Browser:面向 AI 的浏览器自动化工具

英文标题:🔶 Agent-Browser – Browser Automation for AI

Agent-Browser 是一款为 AI Agent 设计的浏览器自动化 CLI,采用原生 Rust 构建,并以紧凑文本输出降低上下文 token 消耗。其 `snapshot` 命令通过带唯一 ref 的无障碍树实现确定性的页面元素定位,相比完整 DOM 可将输出从约 3000—5000 tokens 降至约 200—400 tokens。该工具提供 50 多项命令,覆盖导航、表单、截图、网络、存储、文件、标签页、框架和调试,并支持 Claude Code、Cursor、GitHub Copilot、OpenAI Codex、Google Gemini 等 Agent 工作流。其客户端—守护进程架构可在命令间保持浏览器会话状态,适合需要长期运行的自动化 Agent。
打开原文相关 3 · 机会 2
media22.6 KB

中文

agent-browser#

一款为 AI Agent 设计的浏览器自动化 CLI。紧凑的文本输出可最大限度减少上下文消耗。100% 原生 Rust 构建。

npm install -g agent-browser      # 所有平台
brew install agent-browser        # macOS
agent-browser install             # 下载 Chrome(首次使用)

# 或无需安装即可试用
npx agent-browser open example.com

功能#

  • Agent 优先:紧凑文本输出比 JSON 使用更少 token,专为 AI 上下文效率设计
  • 基于 ref:快照返回带有 ref 的无障碍树,实现确定性的元素选择
  • 功能完整:提供 50 多项命令,覆盖导航、表单、截图、网络、存储、文件、标签页、框架和调试
  • 可观测:内置视频录制、流式传输、调试、性能分析器和差异对比工具
  • 现代应用:网络控制、React 与 Web Vitals、初始化脚本、Next.js + Vercel和eve 扩展工作流均提供一等文档支持
  • 有状态:会话、配置文件、认证状态、Cookie、存储、代理和安全控制支持长期运行的 Agent
  • 跨平台:macOS、Linux、Windows,提供原生二进制文件

可配合以下工具使用#

Claude Code、Cursor、GitHub Copilot、OpenAI Codex、Google Gemini、opencode,以及任何能够运行 Shell 命令的 Agent。

示例#

# 导航并获取快照
agent-browser open example.com
agent-browser snapshot -i

# 输出:
# - heading "Example Domain" [ref=e1]
# - link "More information..." [ref=e2]

# 使用 ref 进行交互
agent-browser click @e2
agent-browser screenshot page.png
agent-browser close

为什么使用 ref?#

snapshot 命令会返回一棵紧凑的无障碍树,其中每个元素都有唯一的 ref,例如 @e1、@e2。这带来以下优势:

  • 节省上下文:文本输出约使用 200—400 tokens,而完整 DOM 约需 3000—5000 tokens
  • 确定性:ref 指向快照中的确切元素
  • 快速:无需重新查询 DOM
  • 对 AI 友好:LLM 可自然解析文本输出

架构#

采用客户端—守护进程架构,以实现最佳性能:

  1. Rust CLI:解析命令并与守护进程通信
  2. 原生守护进程:使用直接 CDP 的纯 Rust 守护进程,通过 Chrome DevTools Protocol 管理 Chrome

守护进程会自动启动,并在各命令之间持续运行。默认情况下,它会保存已配置的恢复状态、关闭无头浏览器,并在一小时内未收到命令或仪表板输入后退出。若未使用 --restore 或其他恢复键,关闭时将丢弃临时浏览器状态和已打开的标签页。有头浏览器、Safari 和 iOS WebDriver 会话,以及用户附加的浏览器不受默认超时限制;由服务提供商管理的云端浏览器则不在豁免范围内。可使用 --idle-timeout <time> 或 AGENT_BROWSER_IDLE_TIMEOUT_MS 调整超时时间,使用 0 可禁用超时。

平台#

为 macOS(ARM64、x64)、Linux(ARM64、x64)和 Windows(x64)提供原生 Rust 二进制文件。

English / 原文

agent-browser#

Browser automation CLI designed for AI agents. Compact text output minimizes context usage. 100% native Rust.

npm install -g agent-browser      # all platforms
brew install agent-browser        # macOS
agent-browser install             # Download Chrome (first time)

# or try without installing
npx agent-browser open example.com

Features#

  • Agent-first : Compact text output uses fewer tokens than JSON, designed for AI context efficiency
  • Ref-based : Snapshot returns accessibility tree with refs for deterministic element selection
  • Complete : 50+ commands for navigation, forms, screenshots, network, storage, files, tabs, frames, and debugging
  • Observable : Video recording, streaming, debugging, profiler, and diffing tools are built in
  • Modern apps : Network control, React & Web Vitals, init scripts, Next.js + Vercel, and eve Extension workflows have first-class docs
  • Stateful : Sessions, profiles, auth state, cookies, storage, proxy, and security controls support long-running agents
  • Cross-platform : macOS, Linux, Windows with native binaries

Works with#

Claude Code, Cursor, GitHub Copilot, OpenAI Codex, Google Gemini, opencode, and any agent that can run shell commands.

Example#

# Navigate and get snapshot
agent-browser open example.com
agent-browser snapshot -i

# Output:
# - heading "Example Domain" [ref=e1]
# - link "More information..." [ref=e2]

# Interact using refs
agent-browser click @e2
agent-browser screenshot page.png
agent-browser close

Why refs?#

The snapshot command returns a compact accessibility tree where each element has a unique ref like @e1, @e2. This provides:

  • Context-efficient : Text output uses ~200-400 tokens vs ~3000-5000 for full DOM
  • Deterministic : Ref points to exact element from snapshot
  • Fast : No DOM re-query needed
  • AI-friendly : LLMs parse text output naturally

Architecture#

Client-daemon architecture for optimal performance:

  1. Rust CLI : Parses commands, communicates with daemon
  2. Native Daemon : Pure Rust daemon using direct CDP, manages Chrome via Chrome DevTools Protocol

The daemon starts automatically and persists between commands. By default, it saves configured restore state, closes its headless browser, and exits after one hour without commands or dashboard input. Without --restore or another restore key, shutdown discards transient browser state and open tabs. Headed browsers, Safari and iOS WebDriver sessions, and user-attached browsers are exempt from the default timeout; provider-owned cloud browsers are not. Use --idle-timeout <time> or AGENT_BROWSER_IDLE_TIMEOUT_MS to tune the timeout, and use 0 to disable it.

Platforms#

Native Rust binaries for macOS (ARM64, x64), Linux (ARM64, x64), and Windows (x64).