Lightpanda Browser

作者 reason-machines2384a003145a無授權條款83 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫3 個月前更新

Expert skill for Lightpanda — the headless browser built in Zig for AI agents and automation. 9x less memory, 11x faster than Chrome. Installation, CLI, CDP server, Playwright/Puppeteer integration, and web scraping.

AI 產生的概覽

介紹輕量級無頭瀏覽器 Lightpanda 的安裝與使用,用於 CDP 自動化與網頁擷取。

功能
此技能介紹以 Zig 撰寫的無頭瀏覽器 Lightpanda,涵蓋在 macOS、Linux 與 Docker 上的安裝、命令列用法以及啟動 CDP 伺服器。它提供 Playwright、Puppeteer、chromedp 與 Python 的整合範例,以及批次擷取與結構化資料抽取的網頁擷取模式。此外也列出支援的 Web API、設定項目、效能比較、原始碼建置步驟與疑難排解。
適用情境
適用於為 AI 代理瀏覽、大規模批次擷取或資源受限的容器化自動化設定與執行 Lightpanda。也適合在需要 CDP 相容但不需要完整視覺化算繪時使用,或在 Lightpanda 與 Chrome/Playwright 之間做選擇時參考。
執行需求
需要 Lightpanda 二進位檔或 Docker 映像,並需要網路存取以下載發行版或拉取映像。用戶端整合需要 Playwright、Puppeteer、chromedp 或 Python Playwright。從原始碼建置需要 Zig 0.15.2、Rust、CMake 及系統相依套件。此技能不附帶指令碼,僅為說明文件。

Lightpanda — Headless Browser for AI & Automation

Skill by ara.so — Daily 2026 Skills collection

Lightpanda is a headless browser built from scratch in Zig, designed for AI agents, web scraping, and automation. It uses 9x less memory and runs 11x faster than Chrome headless.

Key facts:

  • Not based on Chromium, Blink, or WebKit — clean-slate Zig implementation
  • JavaScript execution via V8 engine
  • CDP (Chrome DevTools Protocol) compatible — works with Playwright, Puppeteer, chromedp
  • Respects robots.txt via --obey_robots flag
  • Beta status, actively developed
  • License: AGPL-3.0

Installation

macOS (Apple Silicon)

bash
curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-aarch64-macoschmod a+x ./lightpanda

Linux (x86_64)

bash
curl -L -o lightpanda https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-x86_64-linuxchmod a+x ./lightpanda

Docker

bash
# Supports amd64 and arm64docker run -d --name lightpanda -p 9222:9222 lightpanda/browser:nightly

CLI Usage

Fetch a URL (dump rendered HTML)

bash
./lightpanda fetch --obey_robots --log_format pretty --log_level info https://example.com

Start CDP Server

bash
./lightpanda serve --obey_robots --log_format pretty --log_level info --host 127.0.0.1 --port 9222

This launches a WebSocket-based CDP server for programmatic control.

CLI Flags

FlagDescription
--obey_robotsRespect robots.txt rules
--log_format prettyHuman-readable log output
--log_level infoLog verbosity: debug, info, warn, error
--host 127.0.0.1Bind address for CDP server
--port 9222Port for CDP server
--insecure_disable_tls_host_verificationDisable TLS verification (testing only)

Playwright Integration

Start the CDP server, then connect Playwright to it:

javascript
import { chromium } from 'playwright-core';
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');const context = await browser.contexts()[0] || await browser.newContext();const page = await context.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });const title = await page.title();const content = await page.content();
console.log(`Title: ${title}`);console.log(`HTML length: ${content.length}`);
await browser.close();

Puppeteer Integration

javascript
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://example.com', { waitUntil: 'networkidle0' });
const title = await page.title();const text = await page.evaluate(() => document.body.innerText);
console.log(`Title: ${title}`);console.log(`Body text: ${text.substring(0, 200)}`);
await page.close();await browser.close();

Go (chromedp) Integration

go
package main
import (    "context"    "fmt"    "log"
    "github.com/chromedp/chromedp")
func main() {    allocCtx, cancel := chromedp.NewRemoteAllocator(context.Background(), "ws://127.0.0.1:9222")    defer cancel()
    ctx, cancel := chromedp.NewContext(allocCtx)    defer cancel()
    var title string    err := chromedp.Run(ctx,        chromedp.Navigate("https://example.com"),        chromedp.Title(&title),    )    if err != nil {        log.Fatal(err)    }    fmt.Println("Title:", title)}

Python Integration

python
import asynciofrom playwright.async_api import async_playwright
async def main():    async with async_playwright() as p:        browser = await p.chromium.connect_over_cdp("http://127.0.0.1:9222")        context = browser.contexts[0] if browser.contexts else await browser.new_context()        page = await context.new_page()
        await page.goto("https://example.com", wait_until="networkidle")        title = await page.title()        content = await page.content()
        print(f"Title: {title}")        print(f"HTML length: {len(content)}")
        await browser.close()
asyncio.run(main())

Web Scraping Patterns

Batch Page Fetching

javascript
import { chromium } from 'playwright-core';
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');const context = await browser.newContext();
const urls = [  'https://example.com/page1',  'https://example.com/page2',  'https://example.com/page3',];
for (const url of urls) {  const page = await context.newPage();  await page.goto(url, { waitUntil: 'networkidle' });
  const data = await page.evaluate(() => ({    title: document.title,    text: document.body.innerText,    links: [...document.querySelectorAll('a[href]')].map(a => a.href),  }));
  console.log(JSON.stringify(data, null, 2));  await page.close();}
await browser.close();

Extract Structured Data

javascript
const data = await page.evaluate(() => {  const items = document.querySelectorAll('.product-card');  return [...items].map(item => ({    name: item.querySelector('h2')?.textContent?.trim(),    price: item.querySelector('.price')?.textContent?.trim(),    link: item.querySelector('a')?.href,  }));});

Docker Compose (with your app)

yaml
services:  lightpanda:    image: lightpanda/browser:nightly    ports:      - "9222:9222"    restart: unless-stopped
  scraper:    build: .    depends_on:      - lightpanda    environment:      - BROWSER_WS_ENDPOINT=ws://lightpanda:9222

Supported Web APIs

Lightpanda supports (partial, expanding):

  • DOM tree manipulation and querying
  • JavaScript execution (V8)
  • XMLHttpRequest (XHR)
  • Fetch API
  • Cookie management
  • Network interception
  • Proxy support

Configuration

Environment VariableDescription
LIGHTPANDA_DISABLE_TELEMETRYSet to true to opt out of usage metrics

Performance Comparison

MetricLightpandaChrome Headless
Memory~9x lessBaseline
Speed~11x fasterBaseline
Binary sizeSmall (Zig)Large (Chromium)
RenderingNo visual renderingFull rendering engine

When to Use Lightpanda

Use Lightpanda when:

  • Running AI agents that need to browse the web
  • Batch scraping at scale (memory/CPU savings matter)
  • Automating form submissions and data extraction
  • Running in containers where resources are limited
  • You need CDP compatibility but not full visual rendering

Use Chrome/Playwright instead when:

  • You need pixel-perfect screenshots or PDF generation
  • You need full Web API coverage (Lightpanda is still partial)
  • Visual regression testing
  • Testing browser-specific rendering behavior

Building from Source

Requires: Zig 0.15.2, Rust, CMake, system dependencies.

bash
# Ubuntu/Debian dependenciessudo apt install xz-utils ca-certificates pkg-config libglib2.0-dev clang make curl
# Buildgit clone https://github.com/lightpanda-io/browser.gitcd browserzig build
# Optional: pre-build V8 snapshot for faster startupzig build snapshot_creator -- src/snapshot.binzig build -Dsnapshot_path=../../snapshot.bin

Troubleshooting

Connection refused on port 9222:

  • Ensure ./lightpanda serve is running
  • Check --host 0.0.0.0 if connecting from Docker/remote

Playwright script breaks after update:

  • Lightpanda is beta — Playwright's capability detection may behave differently across versions
  • Pin your Lightpanda version or use nightly consistently

Missing Web API support:

Links

來源與署名

來源:reason-machines/trending-skills位於skills/lightpanda-browser提交2384a00

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架