$ show lightpanda-io/browser
A production-grade headless browser built from scratch in Zig, powered by V8 for JavaScript execution. It implements a vast subset of Web Platform APIs (DOM, CSSOM, HTML/SVG elements, canvas, WebGL, IndexedDB, workers, fetch, WebSocket, etc.) and exposes them through Chrome DevTools Protocol (CDP), WebDriver BiDi, and MCP (Model Context Protocol) servers. Includes a built-in LLM agent mode for natural-language-driven automation, a scripting system (PandaScript) for deterministic replay, and a full network stack with ad blocking, rate limiting, caching, and TLS. Designed for AI agents and automation workloads, it claims significant performance advantages over Chromium in startup time and resource usage. Architecturally, the browser is a monolithic server binary with distinct internal modules: a browser core managing pages, frames, and V8 isolates; a network layer using libcurl with connection pooling and request deduplication; protocol servers (CDP, BiDi, MCP) communicating over WebSocket or HTTP; and an agent subsystem that wraps LLM APIs for task planning and execution. The codebase is heavily tested with hundreds of hand-written HTML conformance tests and runs Web Platform Tests via CI. The engineering demonstrates high craftsmanship: custom arena allocators with V8 memory accounting, compile-time prototype hierarchy reflection for Web IDL bindings, a GCRA rate limiter, a singleflight pattern for request deduplication, and a generic live-collection iterator. While some APIs are stubbed or partially implemented (e.g., WebGL always returns null, video dimensions are hardcoded), the core functionality is extensive and spec-compliant where implemented. The project is actively maintained with nightly orderfile optimizations and regular CI.
The LLM identified 4 files worth highlighting for reuse:
A generic singleflight (request coalescing) implementation. Allows multiple concurrent callers to share one in-flight operation keyed by a digest/hash. The call result is broadcast to all waiters via a completion notification. The implementation uses a Mutex-protected map, handles late arrival, and avoids goroutine-like overhead. This pattern is broadly reusable for any async deduplication scenario (e.g., caching expensive lookups, deduplicating network requests).
A GCRA (Generic Cell Rate Algorithm) based rate limiter with per-host counters. Supports configurable requests-per-second and burst sizes. Idle entries are lazily swept using an adaptive threshold to avoid O(N) scans on every insert. The implementation is self-contained, thread-safe via a mutex, and exposes a simple `tryAcquire` interface. Can be extracted for any IP- or key-based throttling need.
A generic, composable iterator pattern for live DOM collections (NodeList, HTMLCollection, etc.). It is parameterized by an entry field and supports index-based and length-based iteration. Includes a `GenericIterator` struct that reuses a single iterator instance per frame. The implementation is decoupled from specific collection types and could be reused for any array-like live data structure requiring fast indexed access and invalidation-tracking.
A streaming base64 encoder supporting standard, URL-safe, and padding-optional modes. Writes encoded output to any writer interface. Uses a small internal buffer (4 bytes) and produces output in 4-byte chunks. The design is minimal, self-contained, and avoids allocations by writing directly to the underlying writer. Easily reusable for any project needing inline base64 encoding without pulling in a full crypto library.