项目简介
Lightpanda 是专为无头使用而设计的开源浏览器:
-
JavaScript 执行
-
支持 Web API(部分,WIP)
-
通过 CDP (WIP) 与剧作家、木偶师兼容
AI 代理的快速网络自动化,LLM以最小的内存占用进行训练、抓取和测试:
快速启动
从夜间构建安装
您可以从 Linux x86_64 和 MacOS aarch64 的夜间构建中下载最后一个二进制文件。
$ 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 -h
usage: ./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,
转储 URL
$ ./lightpanda-x86_64-linux --dump https://lightpanda.io
info(browser): GET https://lightpanda.io/ http.Status.ok
info(browser): fetch script https://api.website.lightpanda.io/js/script.js: http.Status.ok
info(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 9222
info(websocket): starting blocking worker to listen on 127.0.0.1:9222
info(server): accepting new conn...
CDP 服务器启动后,您可以通过配置来运行 Puppeteer 脚本
browserWSEndpoint
。
'use scrict'
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({
browserWSEndpoint: "ws://127.0.0.1:9222",
});
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:
安装并构建依赖项
一体化构建
您可以运行
make install
将 deps 全部安装在一起(如果您需要开发版本,则可以
make install-dev
)。
请注意,构建任务非常长且消耗 CPU,因为您将从源构建所有依赖项,包括 v8 Javascript 引擎。
逐步建立依赖关系
该项目使用 git 子模块作为依赖项。
要初始化或更新
vendor/
目录中的子模块:
Netsurf
库
Netsurf 库用于 HTML 解析和 DOM 树生成。
对于开发环境,请使用
make install-netsurf-dev
。
Mimalloc
Mimalloc 用作 C 内存分配器。
对于开发环境,请使用
make install-mimalloc-dev
。