Lightpanda#

Lightpanda 是一个用 Zig 从零构建、面向机器的无头浏览器引擎。它启动几乎瞬时,内存占用比 Chrome 少 10 倍,执行速度也快 10 倍。

agent-browser 管理 Lightpanda 的方式与管理 Chrome 相同:启动进程、通过 CDP 连接并在结束时关闭进程。所有下游命令(snapshot、click、fill、screenshot 等)都通过同一条 CDP 协议路径工作。

安装#

在将 Lightpanda 与 agent-browser 一起使用之前,先安装 Lightpanda 二进制文件:

平台命令
macOS(Apple Silicon)curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-aarch64-macos && chmod a+x ./lightpanda
Linux(x86_64)curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-x86_64-linux && chmod a+x ./lightpanda

将二进制文件放到你的 PATH 中的某个位置(例如 /usr/local/bin/lightpanda~/.local/bin/lightpanda)。

如需更多选项,请查看 Lightpanda 安装文档

用法#

使用 --engine 标志选择 Lightpanda:

bash
agent-browser --engine lightpanda open example.com
agent-browser --engine lightpanda snapshot
agent-browser --engine lightpanda screenshot

或者通过环境变量将其设为默认值:

bash
export AGENT_BROWSER_ENGINE=lightpanda
agent-browser open example.com

或者写入你的 agent-browser.json 配置:

json
{
  "engine": "lightpanda"
}

自定义二进制路径#

如果 lightpanda 二进制文件不在你的 PATH 中,请使用 --executable-path

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

与 Chrome 的差异#

Lightpanda 是一个专门构建的无头引擎。部分 Chrome 专属功能不可用:

功能状态
扩展(--extension不支持
持久化配置文件(--profile不支持
存储状态(--state不支持
文件访问(--allow-file-access不支持
有头模式(--headed不适用(仅无头)
截图取决于 Lightpanda 的 CDP 支持

如果你把 --engine lightpanda 与不支持的标志一起使用,agent-browser 会返回清晰的错误。

何时使用 Lightpanda#

Lightpanda 适合用于:

  • 快速网页抓取和数据提取
  • 对速度和低内存占用敏感的 AI 代理工作流
  • 资源受限的 CI/CD 环境
  • 大规模并行自动化

当你需要完整的浏览器兼容性、扩展或持久化配置文件时,请使用 Chrome。