Chrome#

Chrome(以及 Chromium)是默认浏览器引擎。agent-browser 会通过 Chrome DevTools Protocol(CDP)自动发现、启动并管理 Chrome 进程。

二进制发现#

当未提供 --executable-path 时,agent-browser 会按以下顺序查找 Chrome:

平台检查的位置
macOS

/Applications/Google Chrome.app, /Applications/Google Chrome Canary.app, /Applications/Chromium.app, /Applications/Brave Browser.app, Puppeteer 缓存(~/.cache/puppeteer/chrome/PUPPETEER_CACHE_DIR), Chrome for Testing 缓存

Linux

google-chrome, google-chrome-stable, chromium-browser, chromium 在 PATH 中, Puppeteer 缓存(~/.cache/puppeteer/chrome/PUPPETEER_CACHE_DIR), Chrome for Testing 缓存

Windows

%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe, C:\Program Files\Google\Chrome\Application\chrome.exe, C:\Program Files (x86)...\chrome.exe

如果找不到 Chrome,请运行 agent-browser install,从 Chrome for Testing 下载 Chrome。

用法#

Chrome 是默认引擎,因此不需要 --engine 标志:

bash
agent-browser open example.com

如果要显式指定:

bash
agent-browser --engine chrome open example.com

自定义二进制#

使用 --executable-path 指向任意基于 Chromium 的浏览器:

bash
agent-browser --executable-path /path/to/chromium open example.com

或者通过环境变量:

bash
export AGENT_BROWSER_EXECUTABLE_PATH=/path/to/chromium
agent-browser open example.com

Chrome 专属功能#

这些功能仅在 Chrome 中可用:

功能标志
浏览器扩展--extension <path>
持久化配置文件--profile <path>(设置 Chrome 的 --user-data-dir
存储状态--state <path>
文件 URL 访问--allow-file-access
无头截图滚动条--hide-scrollbars false 会保留原生滚动条可见
有头模式--headed
自定义启动参数--args <args>

容器和 CI#

在 Docker、CI runner 或其他沙箱环境中,可能需要禁用 Chrome 的用户命名空间沙箱:

bash
agent-browser --args "--no-sandbox" open example.com

当 agent-browser 检测到容器环境(Docker、Podman、以 root 运行)时,会自动添加 --no-sandbox