Examples
Wait before taking screenshot with PHP and Puppeteer
Heads up before you start
Puppeteer has no official PHP port. The closest equivalent is chrome-php — an actively maintained PHP library that controls headless Chrome over the same DevTools Protocol Puppeteer uses. These examples use chrome-php.
Install chrome-php
composer require chrome-php/chrome chrome-php drives a Chrome or Chromium you already have installed — it does not download its own browser. It uses the CHROME_PATH environment variable if set, and otherwise looks in the standard install locations for your OS.
Take a screenshot and save to file
Wait for the page to settle before taking the screenshot.
<?php
require __DIR__ . '/vendor/autoload.php';
use HeadlessChromium\BrowserFactory;
$browser = (new BrowserFactory())->createBrowser();
$page = $browser->createPage();
$page->navigate('https://www.htmltoimage.com/demo')->waitForNavigation();
// Wait for late content — here an element that appears after 2 seconds.
$page->waitUntilContainsElement('#delayed-banner');
$page->screenshot()->saveToFile('wait.png');
$browser->close(); Find out how to take a full-page screenshot with PHP and Puppeteer.
That was 16 lines of code — plus a browser to run in production
Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:
curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com" Try the Urlbox screenshot API — free trial, no browser babysitting.