当前位置: 首页 > news >正文

Lightpanda:专为 AI 和自动化设计的无头浏览器

​一、软件介绍

Lightpanda 是专为无头模式设计的开源浏览器:

  • Javascript execution  JavaScript 执行
  • Support of Web APIs (partial, WIP)
    支持 Web API(部分,进行中)
  • Compatible with Playwright1, Puppeteer, chromedp through CDP
    兼容 Playwright 1 、Puppeteer、chromedp 通过 CDP

Fast web automation for AI agents, LLM training, scraping and testing:
为 AI 代理、LLM 训练、抓取和测试提供快速网页自动化:

  • Ultra-low memory footprint (9x less than Chrome)
    超低内存占用(比 Chrome 少 9 倍)
  • Exceptionally fast execution (11x faster than Chrome)
    执行速度极快(比 Chrome 快 11 倍)
  • Instant startup  即时启动

文末提供程序和源码下载

二、Install  安装

您可以从文末网盘中下载 Linux x86_64 和 MacOS aarch64 的最新二进制文件。

For Linux  对于 Linux

curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-x86_64-linux && \
chmod a+x ./lightpanda

For MacOS  对于 MacOS

curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-aarch64-macos && \
chmod a+x ./lightpanda

For Windows + WSL2  对于 Windows + WSL2

The Lightpanda browser is compatible to run on windows inside WSL. Follow the Linux instruction for installation from a WSL terminal. It is recommended to install clients like Puppeteer on the Windows host.
Lightpanda 浏览器可以在 WSL 中运行于 Windows 上。从 WSL 终端遵循 Linux 安装说明进行安装。建议在 Windows 主机上安装 Puppeteer 等客户端。

Install from Docker  从 Docker 安装

Lightpanda provides official Docker images for both Linux amd64 and arm64 architectures. The following command fetches the Docker image and starts a new container exposing Lightpanda's CDP server on port 9222.
Lightpanda 为 Linux amd64 和 arm64 架构提供了官方的 Docker 镜像。以下命令会获取 Docker 镜像并启动一个新的容器,在端口 9222 上暴露 Lightpanda 的 CDP 服务器。

docker run -d --name lightpanda -p 9222:9222 lightpanda/browser:nightly

Dump a URL  URL 抓取

./lightpanda fetch --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')
<!DOCTYPE html>

Start a CDP server  启动 CDP 服务器

./lightpanda serve --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...

Once the CDP server started, you can run a Puppeteer script by configuring the browserWSEndpoint.
一旦 CDP 服务器启动,您可以通过配置 browserWSEndpoint 来运行一个 Puppeteer 脚本。

'use strict'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();// Dump all the links from the page.
await page.goto('https://wikipedia.com/');const links = await page.evaluate(() => {return Array.from(document.querySelectorAll('a')).map(row => {return row.getAttribute('href');});
});console.log(links);await page.close();
await context.close();
await browser.disconnect();

Telemetry  遥测

By default, Lightpanda collects and sends usage telemetry. This can be disabled by setting an environment variable LIGHTPANDA_DISABLE_TELEMETRY=true. You can read Lightpanda's privacy policy at: https://lightpanda.io/privacy-policy.
默认情况下,Lightpanda 会收集并发送使用情况遥测数据。可以通过设置环境变量 LIGHTPANDA_DISABLE_TELEMETRY=true 来禁用此功能。您可以在 https://lightpanda.io/privacy-policy 上阅读 Lightpanda 的隐私政策。

Status  状态

Lightpanda is in Beta and currently a work in progress. Stability and coverage are improving and many websites now work. You may still encounter errors or crashes. Please open an issue with specifics if so.
Lightpanda 目前处于 Beta 阶段,仍在开发中。稳定性和覆盖范围正在改进,现在许多网站可以正常工作。您可能仍然会遇到错误或崩溃。如果出现这种情况,请提供具体信息打开一个问题。

Here are the key features we have implemented:
我们已实现的关键功能如下:

  •  HTTP loader (based on Libcurl)
    HTTP 加载器(基于 Libcurl)
  •  HTML parser and DOM tree (based on Netsurf libs)
    HTML 解析器和 DOM 树(基于 Netsurf 库)
  •  Javascript support (v8)
    JavaScript 支持(v8)
  •  DOM APIs  DOM API
  •  Ajax
    •  XHR API
    •  Fetch API (polyfill)
  •  DOM dump
  •  CDP/websockets server  CDP/websockets 服务器
  •  Click  点击
  •  Input form  输入表单
  •  Cookies
  •  Custom HTTP headers
    自定义 HTTP 头
  •  Proxy support  代理支持
  •  Network interception  网络拦截

NOTE: There are hundreds of Web APIs. Developing a browser (even just for headless mode) is a huge task. Coverage will increase over time.
注意:Web API 有数百种。开发浏览器(即使是仅用于无头模式)是一项巨大的任务。覆盖范围将随时间增加。

You can also follow the progress of our Javascript support in our dedicated zig-js-runtime project.
你也可以在我们的专用 zig-js-runtime 项目中关注我们的 JavaScript 支持进度。

三、Build from sources  从源代码构建

Prerequisites  先决条件

Lightpanda is written with Zig 0.15.1. You have to install it with the right version in order to build the project.
Lightpanda 是用 Zig 0.15.1 编写的。你需要安装正确的版本才能构建项目。

Lightpanda also depends on zig-js-runtime (with v8), Libcurl, Netsurf libs and Mimalloc.
Lightpanda 还依赖于 zig-js-runtime(带 v8 版本)、Libcurl、Netsurf 库和 Mimalloc。

To be able to build the v8 engine for zig-js-runtime, you have to install some libs:
要为 zig-js-runtime 构建 v8 引擎,你需要安装一些库:

For Debian/Ubuntu based Linux:
对于基于 Debian/Ubuntu 的 Linux:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>sudo apt install xz-utils \python3 ca-certificates git \pkg-config libglib2.0-dev \gperf libexpat1-dev unzip rsync \cmake clang
</code></span></span></span></span>

For systems with Nix, you can use the devShell:
对于使用 Nix 的系统,您可以使用 devShell:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>nix develop
</code></span></span></span></span>

For MacOS, you only need cmake:
对于 MacOS,您只需要 cmake:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>brew install cmake
</code></span></span></span></span>

Install and build dependencies
安装并构建依赖项

All in one build  一体化构建

You can run make install to install deps all in one (or make install-dev if you need the development versions).
你可以运行 make install 来一次性安装所有依赖(或者运行 make install-dev 如果你需要开发版本)。

Be aware that the build task is very long and cpu consuming, as you will build from sources all dependencies, including the v8 Javascript engine.
请注意,构建任务非常耗时且消耗 CPU,因为你会从源代码构建所有依赖项,包括 v8 JavaScript 引擎。

Step by step build dependency
逐步构建依赖项

The project uses git submodules for dependencies.
该项目使用 git 子模块来管理依赖项。

To init or update the submodules in the vendor/ directory:
要在 vendor/ 目录中初始化或更新子模块:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make install-submodule
</code></span></span></span></span>

iconv

libiconv is an internationalization library used by Netsurf.
libiconv 是一个被 Netsurf 使用的国际化库。

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make install-libiconv
</code></span></span></span></span>

Netsurf libs  Netsurf 库

Netsurf libs are used for HTML parsing and DOM tree generation.
Netsurf 库用于 HTML 解析和 DOM 树生成。

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make install-netsurf
</code></span></span></span></span>

For dev env, use make install-netsurf-dev.
在开发环境中,使用 make install-netsurf-dev 。

Mimalloc

Mimalloc is used as a C memory allocator.
Mimalloc 被用作 C 语言内存分配器。

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make install-mimalloc
</code></span></span></span></span>

For dev env, use make install-mimalloc-dev.
在开发环境中,使用 make install-mimalloc-dev 。

Note: when Mimalloc is built in dev mode, you can dump memory stats with the env var MIMALLOC_SHOW_STATS=1. See https://microsoft.github.io/mimalloc/environment.html.
注意:当 Mimalloc 在开发模式下构建时,你可以通过环境变量 MIMALLOC_SHOW_STATS=1 导出内存统计信息。参见 https://microsoft.github.io/mimalloc/environment.html。

v8

First, get the tools necessary for building V8, as well as the V8 source code:
首先,获取构建 V8 所需的工具以及 V8 源代码:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make get-v8
</code></span></span></span></span>

Next, build v8. This build task is very long and cpu consuming, as you will build v8 from sources.
接下来,构建 v8。这个构建任务非常耗时,因为你要从源代码构建 v8。

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make build-v8
</code></span></span></span></span>

For dev env, use make build-v8-dev.
在开发环境中,使用 make build-v8-dev 。

四、Test  测试

Unit Tests  单元测试

You can test Lightpanda by running make test.
您可以通过运行 make test 来测试 Lightpanda。

End to end tests  端到端测试

To run end to end tests, you need to clone the demo repository into ../demo dir.
要运行端到端测试,你需要将示例仓库克隆到 ../demo 目录。

You have to install the demo's node requirements
你必须安装示例的 node 依赖项

You also need to install Go > v1.24.
你还需要安装 Go > v1.24。

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make end2end
</code></span></span></span></span>

Web Platform Tests  Web 平台测试

Lightpanda is tested against the standardized Web Platform Tests.
Lightpanda 已通过标准化的 Web Platform Tests 进行测试。

The relevant tests cases are committed in a dedicated repository which is fetched by the make install-submodule command.
相关的测试用例已提交到专门的仓库中,该仓库通过 make install-submodule 命令获取。

All the tests cases executed are located in the tests/wpt sub-directory.
所有执行的测试用例都位于 tests/wpt 子目录中。

For reference, you can easily execute a WPT test case with your browser via wpt.live.
作为参考,你可以通过 wpt.live 轻松用你的浏览器执行一个 WPT 测试用例。

Run WPT test suite  运行 WPT 测试套件

To run all the tests:
要运行所有测试:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make wpt
</code></span></span></span></span>

Or one specific test:
或者一个特定的测试:

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>make wpt Node-childNodes.html
</code></span></span></span></span>
Add a new WPT test case
添加新的 WPT 测试用例

We add new relevant tests cases files when we implemented changes in Lightpanda.
当我们在 Lightpanda 中实现变更时,我们会添加新的相关测试用例文件。

To add a new test, copy the file you want from the WPT repo into the tests/wpt directory.
要添加新的测试,将你想从 WPT 仓库中复制的文件放到 tests/wpt 目录中。

⚠️ Please keep the original directory tree structure of tests/wpt.
⚠️ 请保持 tests/wpt 的原始目录树结构。

五、软件下载

夸克网盘

本文信息来源于GitHub作者地址:https://github.com/lightpanda-io/browser

http://www.dtcms.com/a/419350.html

相关文章:

  • 做烘焙的网站网络营销的形式网站营销
  • PyTorch 中模型测试与全局平均池化的应用总结
  • 社交媒体与兴趣电商环境下品类创新机会研究——以“开源AI智能名片链动2+1模式S2B2C商城小程序”为例
  • 【pytorch】数据增强与时俱进,未来的改进和功能将仅添加到 torchvision.transforms.v2 转换中
  • java设计模式:建造者模式
  • 建设银行如何招聘网站动易网站 青春
  • Nginx 高级配置指南:Rewrite、If判断、浏览器分离与防盗链
  • 蓝桥杯嵌入式——基础模块的使用(初始化+调度器+LED+按键+LCD)
  • 厦门专业网站推广建站深圳建设集团是国企吗
  • web开发兼容注意
  • websocket网络通信协议
  • 佛山网站建设的大品牌wordpress远程写作
  • 网站建设的可用性yw55523can优物入口4虎
  • 如何将网站从建站服务商转移出来
  • 使用C#将Markdown转换为Word或PDF:高效文档转换的利器
  • 做淘宝优惠网站坪山网站建设行情
  • c 做网站流程做视频网站的空间
  • 2025 随身 WiFi 行业报告:格行 WiFi6 技术下放百元市场,中兴华为机型竞争力分析;五款机型芯片方案 / 网速 / 质保深度横评
  • Hi3861 OpenHarmony鸿蒙开发(嵌入式方向) (一)
  • Python常用内建模块——XML
  • mapper.xml中limit分页参数不能使用计算表达式问题
  • 精读C++设计模式20 —— 结构型设计模式:桥接模式
  • AI+传统工作流:Photoshop/Excel的智能插件开发指南
  • 冀州网站制作沈阳网站建设索王道下拉
  • java设计模式:抽象工厂模式 + 建造者模式
  • ps做 网站教程服装花型图案设计网站
  • 指令集、立即数和伪指令
  • 危机领导力:突发事件中的决策与沟通策略
  • Unity学习之垃圾回收GC
  • 五次样条速度规划方法介绍