Search by

pushinbr / pam-crawl-browser

DavidWilliamBalbino

JavaScript renderer plugin for pushinbr/pam-crawl: headless Chrome and Lightpanda over CDP, screenshots, PDF, MHTML, sessions and crawl4ai browser parity.

v0.1.3 2026-12-02 19:23 UTC

This package is auto-updated.

Last update: 2026-12-02 19:24:41 UTC


README

🧭 PAM Crawl Browser

JavaScript rendering for PAM Crawl — only when a page needs it.

Lightpanda or Chrome over CDP ¡ screenshots ¡ PDF ¡ sessions ¡ crawl4ai browser parity

PHP 8.5 PAM Runtime Packagist CI PHPStan level 9 License

Documentation ¡ Start here ¡ Examples ¡ Engines ¡ Features ¡ CLI

PAM Crawl reads most of the web without a browser — server-rendered pages, hydration data, the JSON APIs behind apps. This plugin covers the rest: pages that only exist after JavaScript runs, plus everything that needs a real browser (screenshots, PDF, clicks, logins).

  • đŸŽ¯ Only when needed. ->render() fetches over HTTP first and opens a browser only for app shells, bot walls and hosts it learned need JavaScript.
  • đŸĒļ Lightweight by default. Lightpanda renders SPAs with ~42 MB for 8 tabs; Chrome steps in for screenshots, PDF and MHTML.
  • 🧰 Everything crawl4ai's browser does. js_code, wait_for, full-page and virtual scroll, iframes and shadow DOM, consent/overlay removal, stealth, sessions, profiles, network and console capture, downloads, C4A-Script.
  • 🔁 Same API. No new concepts: the crawler you already use gains render(), browser(), js(), waitFor(), screenshot()â€Ļ

Start here

1. Install PAM

curl --proto '=https' --proto-redir '=https' --tlsv1.2 \
    --connect-timeout 15 --max-time 60 --max-filesize 1048576 -fsSL \
    https://pamphp.com/install | sh

pam doctor

2. Create your project

mkdir my-crawler && cd my-crawler
pam composer init --no-interaction
pam composer require pushinbr/pam-crawl pushinbr/pam-crawl-browser

You also need a browser: Google Chrome or Chromium (/usr/bin/google-chrome, or Playwright's Chromium) and, optionally, the Lightpanda binary at ~/.local/share/pam-crawl/bin/lightpanda (see Engines).

3. Create example.php

<?php

declare(strict_types=1);

require __DIR__.'/vendor/autoload.php';

use Pam\Crawl\Crawl;

// 1. Auto mode: plain HTTP first, a browser only for pages that need JavaScript
$page = Crawl::url('https://react.dev/')->render()->get();
echo $page->rendered ? "rendered in a browser\n" : "plain HTTP was enough\n";
echo substr((string) $page->markdown, 0, 300), "\n\n";

// 2. Always render, run JavaScript, wait for an element, take a screenshot and a PDF
$page = Crawl::url('https://news.ycombinator.com/')
    ->browser()
    ->waitFor('css:.athing', 10)
    ->js('return document.querySelectorAll(".athing").length')
    ->screenshot()
    ->capturePdf()
    ->get();

printf("%d stories\n", $page->jsResults[0]);
file_put_contents('hn.png', $page->screenshot);
file_put_contents('hn.pdf', $page->pdfBytes);

// 3. Infinite scroll, consent banners and overlays, a fast engine
foreach (Crawl::urls(['https://example.com/', 'https://www.php.net/'])
    ->engine('lightpanda')            // 'auto' (default), 'chrome', 'lightpanda' or ws://...
    ->scrollFullPage(delay: 0.2)
    ->renderOptions(fn ($o) => $o->with(['removeConsentPopups' => true, 'removeOverlays' => true]))
    ->browser() as $page) {
    printf("%s  %s  (%s)\n", $page->status, $page->url, $page->response->artifacts['renderer']);
}

4. Run it

pam example.php

More scenarios — infinite scroll, logins in one tab, network capture, C4A-Script — live in examples/.

Engines at a glance

Lightpanda Chrome
Memory, 8 tabs ~42 MB, 1 process ~469 MB, 21 processes
SPA render (warm) 0.84 s 0.85 s
JS, waits, scrolling, shadow DOM, stealth, network/console ✅ ✅
Screenshots, PDF, MHTML, geolocation â†Ē falls back to Chrome ✅ (GPU accelerated)
Profiles, downloads — ✅

engine('auto') (default) picks Lightpanda when it is installed and nothing Chrome-only was requested, and retries a page in Chrome if Lightpanda fails. Remote browsers work too: ->engine('ws://host:9222/devtools/browser/â€Ļ') (or wss://).

A quick tour

// Render only what needs it — the rest stays plain HTTP
Crawl::site('https://app.example.com')->render()->depth(2)->each(fn (Page $p) => ...);

// crawl4ai's default: a browser for every page
Crawl::urls($urls)->browser()->each(fn (Page $p) => ...);

// Interact, wait, capture
$page = Crawl::url($url)
    ->js('document.querySelector("#load-more").click()')
    ->waitFor('css:.item:nth-child(40)')
    ->scrollFullPage()
    ->captureNetwork()->captureConsole()
    ->screenshot()->capturePdf()
    ->get();

$page->screenshot;   // PNG bytes        $page->network;    // requests/responses
$page->pdfBytes;     // PDF bytes        $page->console;    // console messages
$page->jsResults;    // script results   $page->rendered;   // true

// Log in once, keep the tab, crawl as that user
Crawl::url('https://example.com/login')->tab('alice')->script(<<<C4A
    SET `#username` "alice"
    SET `#password` "secret"
    CLICK `input[type=submit]`
    WAIT `.dashboard` 10
    C4A)->get();
Crawl::url('https://example.com/account')->tab('alice')->get();

Documentation

Topic
📚 Examples runnable scripts
✨ Features every option, mapped to crawl4ai
âš™ī¸ Engines Chrome, Lightpanda, remote CDP, TLS, network bodies, iframes
âŒ¨ī¸ CLI builtin browser, crawl cdp, profiles, shrink
đŸ—ī¸ Architecture and testing how it works, running the tests

Responsible use

Rendering costs the sites you visit more than plain HTTP: prefer ->render() (auto) over ->browser(), keep tab counts and per-host concurrency polite, respect robots.txt and each site's terms of service, and never use stealth features to bypass access controls.

License

Open source under the Apache License 2.0. See NOTICE. Lightpanda (AGPL-3.0) is launched as an external program and is neither bundled nor linked.

This product includes software developed by UncleCode (https://x.com/unclecode) as part of the Crawl4AI project (https://github.com/unclecode/crawl4ai).