引言
「Not a Chromium fork. Not a WebKit patch.」
这是「一天一个开源项目」系列的第 252 篇。今天的项目是 Lightpanda,一个专门给 AI Agent 和自动化任务用的无头浏览器。
现在的网页大多靠 JavaScript 驱动,SPA、Ajax、React/Vue/Angular 随处可见,光发 HTTP 请求往往拿不到真正的内容。于是大家把 Headless Chrome 拉起来跑爬虫、跑 Agent。可 Chrome 本来是给人看页面设计的,带着一整套无头场景根本用不上的东西:渲染管线、GPU、各种面向用户的功能。规模一上去,内存、启动速度和部署成本都成了问题。
Lightpanda 的做法是干脆不改 Chrome,直接用 Zig 重写一个浏览器:保留 HTML 解析、DOM、V8 执行 JavaScript、网络请求这些「拿到页面内容」必须有的部分,砍掉图形渲染。代价是 Web 兼容性要自己一点点追,换来的是资源占用的数量级下降。
你将学到什么
- 为什么「不做渲染」能让无头浏览器的内存和速度差出一个数量级
- Lightpanda 的组件选型:Zig + V8 + libcurl + html5ever
- fetch、serve、mcp、agent 四种使用方式分别适合什么场景
- PandaScript:把一次 Agent 会话固化成不耗 token 的确定性脚本
- 它目前的边界:兼容性、平台支持与许可证上需要注意什么
前置知识
- 了解无头浏览器(Headless Chrome、Puppeteer、Playwright)的基本用法
- 知道 CDP(Chrome DevTools Protocol)是什么
- 可选:了解 MCP(Model Context Protocol)
项目背景
项目简介
官方对自己的定位很直接:为 AI Agent 和自动化设计的无头浏览器,用 Zig 编写的全新浏览器。设计上有三个明确选择:
- 不基于 Chromium、Blink 或 WebKit
- 用 Zig,以便显式控制内存
- 没有图形渲染引擎
项目数据
- ⭐ GitHub Stars:约 40,700
- 🍴 Forks:约 1,990
- 💻 主要语言:Zig
- 📅 创建时间:2023-02-07
- 📄 许可证:AGPL-3.0(商用或集成进闭源产品前务必先看清楚)
- 💬 社区:Discord;贡献代码需要签署 CLA
主要功能
核心作用
用 Headless Chrome 跑 Agent / 爬虫:
一个完整的浏览器进程 → 内存大、启动慢、部署重
↑ 并发一高,成本主要花在「用不上的渲染能力」上
Lightpanda 的做法:
只保留 HTTP 加载 + HTML 解析 + DOM + V8 执行 JS
↓ 不渲染画面
↑ 同样的页面,内存和耗时都大幅下降
官方基准测试
在 AWS EC2 m5.large 上请求 933 个真实页面:
这是项目方自己发布的数据,测的是「抓取页面内容」这类任务。需要截图级渲染、复杂交互的场景不能直接套用。
使用场景
- 大规模页面抓取:需要执行 JS 才能拿到内容,但不想为每个页面付一个 Chrome 的成本
- 给 AI Agent 提供浏览能力:通过 MCP Server 或 CDP 接入
- 替换现有 Puppeteer/Playwright 脚本的后端:只改连接端点,脚本基本不用动
- 把 Agent 探索出的流程固化:用 PandaScript 重放,不再消耗 token
快速开始
安装
# macOS / Linux (Homebrew)
brew install lightpanda-io/browser/lightpanda
# Arch Linux
yay -S lightpanda-nightly-bin
# Nix
nix run github:lightpanda-io/browser -- --help
也可以下载 Linux、macOS(x86_64 与 aarch64)的 nightly 二进制,或使用官方 Docker 镜像 lightpanda/browser(amd64/arm64,CDP 端口 9222)。Windows 没有原生版本,需要用 WSL2。
抓取一个页面
# 输出为 html / markdown / png / pdf / structured_data 等
lightpanda fetch --dump markdown https://example.com
可以用 --wait-until、--wait-ms、--wait-selector、--wait-script 控制等待时机,--obey-robots 遵守 robots.txt。structured_data 格式会提取 JSON-LD、OpenGraph 等结构化数据。
作为 CDP 服务器给 Puppeteer 用
lightpanda serve --host 127.0.0.1 --port 9222
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://127.0.0.1:9222',
});
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await browser.disconnect();
除了 CDP,serve 还支持 Unix socket 和 WebDriver BiDi(--protocol webdriver,或两种协议同时开启)。
核心特性
- 协议:CDP over WebSocket、WebDriver BiDi
- 网页能力:HTTP 加载(libcurl)、HTML 解析(html5ever)、DOM、JavaScript(V8)、XHR 与 Fetch、CORS、Cookie、自定义 Header、代理、网络拦截、点击与表单输入
- 其他:robots.txt 支持、广告拦截
- MCP Server:lightpanda mcp,stdio 上跑 JSON-RPC 2.0,也可加 --port 以 HTTP 方式提供 /mcp
- 原生 Agent:lightpanda agent,用自然语言或斜杠命令驱动,支持 Anthropic、OpenAI、Gemini、Vertex AI、Mistral、Hugging Face、OpenRouter、任意 OpenAI 兼容端点,以及 Ollama、llama.cpp 等本地模型
项目详细剖析
少一层渲染,到底省在哪
浏览器的大头开销往往在渲染:样式计算、布局、绘制、合成、GPU 进程。对一个只想要「执行完 JS 之后的 DOM」的 Agent 来说,这些都是白花的资源。Lightpanda 保留的是一条精简的流水线:
URL → libcurl 加载 → html5ever 解析 → DOM 树 → V8 执行脚本
→ 输出 HTML / Markdown / 结构化数据 / CDP 事件
没有绘制这一步,也就不需要为它准备的内存结构。再加上 Zig 允许显式管理内存,这就是官方数据里 16 倍内存差距的由来。需要说明的是,fetch 命令列了 png 和 pdf 输出,具体效果以官方文档和你的实际页面为准;它的主要定位仍然是内容抓取而不是像素级渲染。
组件选型:不重造所有轮子
Lightpanda 自己写的是浏览器的骨架和 Web API 层,底层几个最重的部件直接用成熟库:
这是一个务实的选择:JS 引擎和 HTML5 解析规范都极其复杂,自己写既不现实也没必要。代价是构建依赖变重,需要 Zig 0.17.0、V8、libcurl,以及 Rust 工具链,自己编译的门槛不低。
四种入口,对应四类需求
MCP 模式里,会话默认相互隔离;共用同一个 Mcp-Session-Id 的客户端共享一个浏览上下文,并有 session_new、session_list、session_close 管理会话。run 工具用来执行 PandaScript,默认超时 60000 毫秒。
PandaScript:把 Agent 的探索变成确定性脚本
这是我觉得最有意思的设计。让 LLM 每次都去「看页面、决定点哪里」既慢又烧 token。Lightpanda 的 agent 会话可以用 /save 保存成一段带有浏览器原语的 JavaScript,之后用 lightpanda run script.js 重放,不需要模型、不消耗 token。
第一次:Agent 探索 → 找到可行路径 → /save 成脚本
之后:lightpanda run script.js → 确定性重放,零 token
这等于把「LLM 当探路者,脚本当执行者」做进了工具本身。页面改版导致脚本失效时,再让 Agent 重新探索即可。
兼容性:用 WPT 说话
新浏览器最大的风险是「某个页面跑不起来」。项目方每天公开 Web Platform Tests 的结果(perf.lightpanda.io/wpt),所以覆盖率不靠宣传,可以自己查。落地前建议拿你要访问的目标站点实测一遍,别只看基准测试。
需要注意的边界
- 许可证是 AGPL-3.0:把它放进对外提供的服务或闭源产品前,要评估网络使用条款带来的义务
- 平台:没有 Windows 原生版本;Linux 二进制依赖 glibc(x86_64 需 2.35,arm64 需 2.38),Alpine/musl 不能用;没有 Android/Termux 版本
- 遥测默认开启:可通过环境变量 LIGHTPANDA_DISABLE_TELEMETRY=true 关闭
- README 没有逐项列出尚未支持的 Web API:是否适配你的目标站点,要靠自己测试
项目地址与资源
- 🌟 GitHub:github.com/lightpanda-…
- 📊 WPT 结果:perf.lightpanda.io/wpt
- 🐳 Docker 镜像:lightpanda/browser
- 🧩 Agent Skill:lightpanda-io/agent-skill
- 💬 社区:项目 README 中的 Discord 链接
总结与展望
核心要点回顾
- 思路:为「拿内容」而不是「给人看」设计浏览器,去掉渲染
- 数据:官方测试 100 页内存 123MB vs 2GB,耗时 5 秒 vs 46 秒
- 兼容:CDP 和 WebDriver BiDi,Puppeteer/Playwright 可直接连
- AI 原生:内置 MCP Server、多模型 Agent,以及零 token 重放的 PandaScript
- 边界:AGPL-3.0、平台限制、Web 兼容性要自行验证
适用人群
- 需要大规模抓取动态页面、被 Chrome 资源占用拖累的团队
- 给 AI Agent 搭建浏览能力的开发者
- 想把 Agent 探索流程固化、降低 token 成本的人
学习建议
先用 fetch 抓几个你自己关心的页面,对比 Chrome 的输出是否一致;再用 serve 把一小段现有 Puppeteer 脚本切过来跑,看兼容性和资源占用是否符合预期。确认没问题再考虑上规模。
欢迎访问 PrimeSkills —— 一个精心策划的 AI Agent 与技能市场,所有内容均经过真实企业级工作流验证。没有噱头,只有真正有效的东西。
更多实用知识和有趣产品,欢迎访问我的个人主页
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Introduction
「Not a Chromium fork. Not a WebKit patch.」
This is part 252 of the "One Day Open Source Project" series. Today's project is Lightpanda, a headless browser dedicated to AI Agent and automated missions.
Most of the current web pages are driven by JavaScript, with SPA, Ajax, React/Vue/Angular everywhere, and light-headed HTTP requests often fail to get real content. So we pulled Headless Chrome up and ran Agent. But Chrome was designed to look at the page, with a set of headlines that were not useful at all: rendering lines, GPUs, various user-oriented features. On a scale, memory, start-up speed and deployment costs are at stake.
Lightpanda's approach is simply not to change Chrome and to rewrite a browser with Zig: to keep HTML resolution, DOM, V8 to execute JavaScript, and the Internet to request these "get the page" parts, cutting off graphics. The price is for Web compatibility to follow itself a little bit, in return for a decline in the amount of resources spent.
What will you learn?
- Why doesn't "no rendering" make headless browser memory and speed vary by one order of magnitude?
- Component selection for Lightpanda: Zig + V8 + libcurl + html5ever
- Fetch, service, mcp, angent, each of the four ways in which it works.
- PandaScript: solidise an Agent session into a sure token script
- Its current boundaries: compatibility, platform support and licensing needs attention
Pre-knowledge
- Understanding the basic uses of Headless Crome, Puppeteer, Playwright
- Know what CDP is?
- Options: Understanding MCP
Project background
Project Profile
The official location is direct: a headless browser designed for AI Agent and for automation, a new browser created by Zig. There are three clear design options:
- Not based on Chromium, Blink or WebKit.
- Use Zig for visible memory control
- There's no graphic rendering engine.
Project data
- GitHub Stars: around 40,700
- Forks: about 1,990
- Main language: Zig
- Creation time: 2023-02-07
- Licence: AGPL-3.0 (must see clearly before commercial or integrated closed source products)
Community: Discord; contribution code to sign CLA
Main functions
Core role
Run Agent/ reptile with Headless Chrome:
A complete browser process – large memory, slow start, deployment Heavy
It's a lot of money. Move!
Lightpanda:
Only keep HTTP loading + HTML parsing + DOM + V8 to execute JS
No image.
The same page, memory and time-consuming, has dropped dramatically.
Official benchmark tests
Requesting 933 real pages on AWS EC2 m5.large:
This is the projecter's own publish data, which measure tasks such as "capturing page contents". The complex interactive scene, which requires a sorting rendering, cannot be applied directly.
Use scene
- Large-scale page grab: JS needs to be executed to get content, but does not want to pay a Shrome for each page
- Provide a browsing capability for AI Agent: access via MCP Server or CDP
- Replaces the backend of the existing Puppeter/Playwright script: only connects the endpoint, and the script is almost intact
- Stabilize processes explored by Agent: re-play with PandaScript, no more token
Fast start.
Install
# macOS / Linux (Homebrew)
brew install lightpanda-io/browser/lightpanda
# Arch Linux
yay -S lightpanda-nightly-bin
# Nix
nix run github:lightpanda-io/browser -- --help
You can also download the Lightly Binary of Linux, MacOS (x86 64 and aarch64) or use the official Docker mirror lightpanda/browser (amd64arm64, CDP port 9222). Windows doesn't have original versions that need WSL2.
Capture a page
# Output is html / markdown / png /pdf / written data, etc.
lightpanda fetch --dump markdown https://example.com
Waiting times can be controlled by --wait-until, --wait-ms, --wait-selector, --wait-scripts -- obey-robots to comply with robots.txt. The structured data format extracts structured data such as JSON-LD and OpenGraph.
As a CDP server for Puppeteer
lightpanda serve --host 127.0.0.1 --port 9222
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://127.0.0.1:9222',
});
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await browser.disconnect();
In addition to CDP,serve supports Unix socket and WebDriver BiDi (-protocol webdriver, or both).
Core characteristics
- Agreements: CDP over WebSocket, WebDriver BiDi
- Web capacity: HTTP load (libcurl), HTML resolution (html5ever), Dom, JavaScript (V8), XHR and Fetch, CORS, Cookie, Custom Header, Agent, Web Interception, Click and Form Input
- Other: robots.txt support, advertising interception
- MCP Server: brightpanda mcp, stdio running JSON-RPC 2.0 and -port provided in HTTP/ mcp
- Native:lightpanda anent, driven by natural language or slash command, supports local models such as Anthropic, Open AI, Gemini, Vertex AI, Mistral, Hugging Face, OpenRouter, any Open AI compatibility endpoint, and Ollama, llama.cpp
Detailed Project Profile
What's the difference?
The bulk of the browser 's costs are often rendered: style computing, layout, drawing, synthesis, GPU processes. These are the resources of the white flower for an Agent who only wants to "dom after JS." Lightpanda retains a lean line:
URL → libcurl load → html5ever parsing →DOM tree → V8 execution script
Output HTML/ Markdown/ Structured Data / CDP Event
Without this step, there is no need for the memory structure for it. Plus Zig allows visible memory management, which is the origin of the 16-fold memory gap in official data. It should be noted that the fech command lists the png and pdf outputs, the effects of which are based on the official document and your actual page; its main location remains content capture rather than pixel rendering.
Component selection: Do not recreate all wheels
Lightpanda writes for itself the skeleton of the browser and the Web API layer, with several of the most heavy components at the bottom directly using mature libraries:
This is a pragmatic choice: JS engines and HTML5 are extremely complex, and writing themselves is neither realistic nor necessary. The cost is to build a heavy reliance on Zig 0.17.0, V8, libcurl, and Rust ' s tool chain, with a threshold for self-compilation.
Four portals, four types of needs.
In MCP mode, the session is separated by default; the client sharing the same McP-session-Id shares a browsing context and has a session new, session list, session close management session. Run tools to execute PandaScript, default timeout 60000 ms.
PandaScript: Turn Agent's exploration into a definitive script
This is the most interesting design I've ever had. LLM is allowed to "see the page, decide where the point" every time. Lightpanda's delegate session can be saved as a JavaScript with the browser's original language, and is then replayed with lightpanda run script.js without needing a model and without consumption token.
First: Agent explores and finds a viable path / save into script
After: lightpanda run script.js → Replay certainty, zero token
It's like putting "LLM as a tracker, script as an implementer" in the tool itself. If you change the page to render the script invalid, then Agent can rediscover it.
Compatibility: Speak with WPT
The biggest risk for the new browser is that a page cannot run. The results of Web Platform Tests (perf.lightpanda.io/wpt) are made public daily by projecters, so coverage is not based on publicity and can be self-censored. Before landing, it is recommended that the target sites that you want to visit be measured, not just the benchmark tests.
Borders that require attention
- Licence AGPL-3.0: Before putting it in a service provided externally or in a closed-source product, assess the obligations arising from the use of the web
- Platform: no original version of Windows; Linux binary dependent glibc (x86 64 required 2.35, arm64 2.38), Alpine/musl not available; no Android/Termux version
- Telemetry Default Start: The environment variable LIGHTPANDA DISABLE TELEMETRY=tru
- README does not list unsupported Web APIs: Suitability of your target sites is tested on its own
Project address and resources
- 🌟 GitHub:github.com/lightpanda-…
- WPT results: perf.lightpanda.io/wpt
- Docker mirror: lightpanda/browser
- 🧩 Agent Skill:lightpanda-io/agent-skill
- Community: Discord Link in README
Summary and outlook
Review of core elements
- Thinking: Designing browsers for "take the contents" instead of "seeing them."
- Data: official test 100 page memory 123MB vs 2GB, 5 seconds vs 46 seconds
- Compatibility: CDP and WebDriver BiDi, Puppeter/Playwright directly linked
- AI Native: Inline MCP Server, Multimodel Agent, and zero token reset PandaScript
- Boundaries: AGPL-3.0, platform limits, Web compatibility to be self-verified
Population applicable
- Teams that need large-scale capture of dynamic pages that are drawn into the Chrome resource
- Developer of the ability to build browsing for AI Agent
- People who want to fix and reduce token's costs.
Learning advice
Take a few pages of your own concern first, and compare the output of Chrome to the same; then use serve to cut down a little bit of the existing Puppeter script and see if compatibility and resource occupancy are expected. Make sure there's no problem.
Welcome to PrimeSkills - a well-planned AI Agent and skills market, all of which has been validated by real enterprise-level workflow. There's no twitch, there's only something that really works.
More practical knowledge and interesting products. Welcome to my home page.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.