Skip to content

PAM Browser

pushinbr/pam-browser is a small, typed Chrome DevTools Protocol (CDP) client for PHP applications running on PAM. It launches Chrome or Chromium as a supervised child process, connects to it over a WebSocket, and gives you pages you can navigate, evaluate JavaScript in, screenshot, and listen to.

There is no Node.js, npm, Puppeteer, or Playwright involved. The browser stays an external process; everything you write is PHP.

Use it when you need a real browser engine from a long-lived PHP process: rendering JavaScript-heavy pages, taking screenshots, or bridging a web app into PHP. It is also the browser layer under PAM WhatsApp Web, PAM Telegram Web, and the PAM Crawl browser plugin.

title.php
<?php
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
use Pam\Browser\Browser;
$browser = Browser::launch();
try {
$page = $browser->newPage('https://example.com');
echo $page->evaluate('document.title'), PHP_EOL;
} finally {
$browser->close();
}
  • The PAM runtime (see Installation). The package requires PHP 8.5 or newer, which PAM ships.
  • Google Chrome or Chromium installed on the host. PAM Browser does not download a browser for you.

PAM Browser looks for an executable named google-chrome-stable, google-chrome, chromium, chromium-browser, or chrome on your PATH. Set the PAM_CHROME_PATH environment variable to point it somewhere else:

Terminal window
export PAM_CHROME_PATH=/opt/google/chrome/chrome

Install the package with PAM’s Composer passthrough:

Terminal window
mkdir browser-demo && cd browser-demo
pam composer init --no-interaction
pam composer require pushinbr/pam-browser:^1.0

Create title.php with the example from the introduction and run it:

Terminal window
pam title.php
Example Domain

Here is what happened:

  1. Browser::launch() started Chrome in headless mode with a temporary profile and a random local debugging port.
  2. newPage() created a new tab, attached a CDP session to it, and waited for the load event of the URL.
  3. evaluate() ran document.title in the page and returned the value as a PHP string.
  4. close() asked Chrome to exit, closed the WebSocket, stopped the process, and deleted the temporary profile.
your PHP code
│
▼
PAM Browser ──── typed Browser and Page objects
│ CDP over a local WebSocket (ws://127.0.0.1:<port>)
▼
Chrome / Chromium (child process, headless by default)
  • Chrome is started with --remote-debugging-address=127.0.0.1 and --remote-debugging-port=0, so the debugging endpoint is bound to loopback on a free port. PAM Browser reads the actual endpoint from the profile’s DevToolsActivePort file.
  • The WebSocket client is written in PHP and uses PAM’s native stream API (Pam\Stream\Streams), so it does not depend on a third-party WebSocket library.
  • Commands are synchronous from your point of view: evaluate() sends a command and waits for its response, routing any events that arrive in between to your listeners.