项目简介
Lightpanda 是专为无头使用而设计的开源浏览器:
-
JavaScript 执行
-
支持 Web API(部分,WIP)
-
通过 CDP (WIP) 与剧作家、木偶师兼容
AI 代理的快速网络自动化,LLM以最小的内存占用进行训练、抓取和测试:
-
超低内存占用(比 Chrome 少 9 倍)
-
执行速度极快(比 Chrome 快 11 倍)和即时启动

快速启动
从夜间构建安装
您可以从 Linux x86_64 和 MacOS aarch64 的夜间构建中下载最后一个二进制文件。
# Download the binary$ wget https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-x86_64-linux$ chmod a+x ./lightpanda-x86_64-linux$ ./lightpanda-x86_64-linux -husage: ./lightpanda-x86_64-linux [options] [URL]start Lightpanda browser* if an url is provided the browser will fetch the page and exit* otherwhise the browser starts a CDP server-h, --help Print this help message and exit.--host Host of the CDP server (default "127.0.0.1")--port Port of the CDP server (default "9222")--timeout Timeout for incoming connections of the CDP server (in seconds, default "3")--dump Dump document in stdout (fetch mode only)
转储 URL
$ ./lightpanda-x86_64-linux --dump https://lightpanda.ioinfo(browser): GET https://lightpanda.io/ http.Status.okinfo(browser): fetch script https://api.website.lightpanda.io/js/script.js: http.Status.okinfo(browser): eval remote https://api.website.lightpanda.io/js/script.js: TypeError: Cannot read properties of undefined (reading 'pushState')
启动 CDP 服务器
$ ./lightpanda-x86_64-linux --host 127.0.0.1 --port 9222info(websocket): starting blocking worker to listen on 127.0.0.1:9222info(server): accepting new conn...
CDP 服务器启动后,您可以通过配置来运行 Puppeteer 脚本 browserWSEndpoint 。
'use scrict'import puppeteer from 'puppeteer-core';// use browserWSEndpoint to pass the Lightpanda's CDP server address.const browser = await puppeteer.connect({browserWSEndpoint: "ws://127.0.0.1:9222",});// The rest of your script remains the same.const context = await browser.createBrowserContext();const page = await context.newPage();await page.goto('https://wikipedia.com/');await page.close();await context.close();
从源头构建
先决条件
Lightpanda 是用Zig 0.13.0编写的。您必须使用正确的版本安装它才能构建项目。
Lightpanda 还依赖于 zig-js-runtime (带有 v8), Netsurf 库和 米马洛克。
为了能够为 zig-js-runtime 构建 v8 引擎,您必须安装一些库:
For Debian/Ubuntu based Linux:
对于基于 Debian/Ubuntu 的 Linux:
sudo apt install xz-utils \python3 ca-certificates git \pkg-config libglib2.0-dev \gperf libexpat1-dev \cmake clang
对于 MacOS,您只需要 cmake:
brew install cmake
安装并构建依赖项
一体化构建
您可以运行make install将 deps 全部安装在一起(如果您需要开发版本,则可以make install-dev )。
请注意,构建任务非常长且消耗 CPU,因为您将从源构建所有依赖项,包括 v8 Javascript 引擎。
逐步建立依赖关系
该项目使用 git 子模块作为依赖项。
要初始化或更新vendor/目录中的子模块:
make install-submodule
Netsurf库
Netsurf 库用于 HTML 解析和 DOM 树生成。
make install-netsurf
对于开发环境,请使用make install-netsurf-dev 。
Mimalloc
Mimalloc 用作 C 内存分配器。
make install-mimalloc
对于开发环境,请使用make install-mimalloc-dev 。
注意:当 Mimalloc 在开发模式下构建时,您可以使用环境变量MIMALLOC_SHOW_STATS=1转储内存统计信息。看 https://microsoft.github.io/mimalloc/environment.html 。
zig-js 运行时
我们自己的 Zig/Javascript 运行时,其中包括 v8 Javascript 引擎。
此构建任务非常长且消耗 CPU,因为您将从源代码构建 v8。
make install-zig-js-runtime
对于开发环境,使用 make iinstall-zig-js-runtime-dev 。
项目链接
https://github.com/lightpanda-io/browser
扫码加入技术交流群,备注「开发语言-城市-昵称」
(文:GitHubStore)