pushinbr / pam-crawl-browser
JavaScript renderer plugin for pushinbr/pam-crawl: headless Chrome and Lightpanda over CDP, screenshots, PDF, MHTML, sessions and crawl4ai browser parity.
Requires
- php: ^8.5
- ext-json: *
- pushinbr/pam-browser: ^1.0
- pushinbr/pam-crawl: ^0.1.3
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
- ext-gd: Stitch very tall full-page screenshots into one PNG
Provides
None
Conflicts
None
Replaces
None
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
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).