专栏名称: GitHubStore
分享有意思的开源项目
目录
相关文章推荐
中国城市规划  ·  天下事 | “2024年中国考古新发现”,揭晓! ·  2 天前  
中国城市规划  ·  理论研究 | 王明田:县城体检指标与方法 ·  3 天前  
中国城市规划  ·  理论研究 | ... ·  5 天前  
51好读  ›  专栏  ›  GitHubStore

专为自动化任务设计的开源无头浏览器

GitHubStore  · 公众号  ·  · 2025-01-18 09:37

正文

项目简介

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







请到「今天看啥」查看全文