Skip to content

PAM Crawl Browser

PAM Crawl reads most of the web without a browser: server-rendered pages, hydration data and the JSON APIs behind apps. pushinbr/pam-crawl-browser covers the rest: pages that only exist after JavaScript runs, and everything that needs a real browser, such as screenshots, PDFs, clicks and logins.

It is a plugin, not a new API. Once installed, the crawler you already use gains render(), browser(), js(), waitFor(), screenshot() and friends:

  • Only when needed. ->render() fetches over HTTP first and opens a browser only for app shells, bot walls and hosts it has learned need JavaScript.
  • Lightweight by default. Lightpanda renders single-page apps with a fraction of Chrome’s memory; Chrome steps in for screenshots, PDF and MHTML.
  • Crawl4AI browser parity. js_code, wait_for, full-page and virtual scroll, iframes and shadow DOM, consent and overlay removal, stealth, sessions, profiles, network and console capture, downloads and C4A-Script.
  • One PHP thread. It drives browsers over the Chrome DevTools Protocol (through pushinbr/pam-browser) with no Node.js and no extensions beyond json and dom.
  • PHP 8.5 on the PAM runtime (or plain PHP 8.5)
  • pushinbr/pam-crawl 0.1.3 or later (installed automatically)
  • Google Chrome or Chromium, and optionally Lightpanda
  • Optional: the gd extension, to stitch very tall full-page screenshots into one PNG
Terminal window
mkdir my-crawler && cd my-crawler
pam composer init --no-interaction
pam composer require pushinbr/pam-crawl pushinbr/pam-crawl-browser

Install Google Chrome or Chromium with your system’s package manager. The plugin looks for it, in order, at /usr/bin/google-chrome, in Playwright’s Chromium download, and on your PATH. Point it anywhere else with the PAM_CRAWL_CHROME environment variable:

Terminal window
export PAM_CRAWL_CHROME=/opt/chromium/chrome

Most settings are crawler methods, so there is nothing to configure up front. The plugin reads these environment variables:

Variable Purpose
PAM_CRAWL_CHROME Path to the Chrome or Chromium binary
PAM_CRAWL_LIGHTPANDA Path to the Lightpanda binary
PAM_CRAWL_SOFTWARE_GL=1 Turn off GPU rendering in Chrome, for machines without a GPU

Chrome runs on the GPU by default (ANGLE over EGL, never SwiftShader). On servers and containers without a GPU, set PAM_CRAWL_SOFTWARE_GL=1. For full control, create the renderer yourself with a BrowserConfig; see Engines.

render.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://quotes.toscrape.com/js/')->render()->get();
echo $page->rendered ? "rendered in a browser\n" : "plain HTTP was enough\n";
echo $page->content->raw, "\n\n";
// 2. Always render, wait for an element, run JavaScript, capture a screenshot and a PDF
$page = Crawl::url('https://quotes.toscrape.com/js/')
->browser()
->waitFor('css:div.quote', 10)
->js('return document.querySelectorAll("div.quote").length')
->screenshot()
->capturePdf()
->get();
printf("%d quotes\n", $page->jsResults[0]);
file_put_contents('quotes.png', $page->screenshot);
file_put_contents('quotes.pdf', $page->pdfBytes);
Terminal window
pam render.php

The first request is an app shell, so render() opens a browser for it; a server-rendered page such as https://quotes.toscrape.com/ would stay on plain HTTP. Browsers start lazily on first use and stop when the script ends.

From the command line, --render does the same:

Terminal window
pam crawl https://quotes.toscrape.com/js/ --render -o md-fit
pam crawl https://app.example.com --render always --engine chrome
Method Behaviour Use it when
->render() HTTP first; render app shells, bot walls and hosts learned to need it Crawling a mix of pages (recommended)
->browser() Render every page (Crawl4AI’s default) Every page needs JavaScript, or you need captures
Browser-only methods js(), waitFor(), screenshot(), capturePdf()… imply rendering You need the browser for that page

render() and browser() also accept your own renderer instance, and render() takes a RenderMode (Never, Auto, Always) as its second argument.

Rendering costs the sites you visit more than plain HTTP: it loads their scripts, styles and images. Prefer ->render() 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. Read Responsible Use.


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