跳转至

Lightpanda

Lightpanda 是一款从头开始用 Zig 构建的、面向机器的无头浏览器引擎。它启动即时,内存占用比 Chrome 少 10 倍,执行速度快 10 倍。

agent-browser 管理 Lightpanda 的方式与它管理 Chrome 的方式相同——启动进程、通过 CDP 连接、然后关闭它。所有下游命令(snapshot、click、fill、screenshot 等)都通过相同的 CDP 协议路径工作。

安装

在使用 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:

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

或者通过环境变量将其设置为默认引擎:

export AGENT_BROWSER_ENGINE=lightpanda
agent-browser open example.com

或者在 ~/.agent-browser/config.json 或通过 --config 加载的文件中:

{
  "engine": "lightpanda"
}

自定义二进制文件路径

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

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 非常适合以下场景:

  • 快速的 Web 抓取和数据提取
  • 注重速度和低内存的 AI 代理工作流
  • 资源受限的 CI/CD 环境
  • 大规模并行自动化

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

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 agen/agent-browser