October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Take a Webpage Screenshot with PHP, Guzzle, and Headless Chrome

Use chrome-php/chrome to render a webpage in headless Chrome and save a screenshot from PHP. Guzzle remains useful for separate HTTP requests, not for rendering the capture.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a webpage in PHP, use chrome-php/chrome to control headless Chrome or Chromium, then save the page’s screenshot. Guzzle is an HTTP client, not the renderer in this flow; keep it for separate HTTP requests your application needs. The distinction matters: installing Guzzle alone will not turn a webpage into a screenshot.

How the pieces fit together

The screenshot flow is: Composer installs the Chrome-control library, PHP starts a Chrome or Chromium process, the library opens a page and navigates to the URL, then the page screenshot method saves an image. The chrome-php/chrome project documents this browser-driven approach. Guzzle provides HTTP requests and configurable handlers, as described in its documentation; it can support other work in the same application, but it does not render the page in this example.

As an Amazon Associate I earn from qualifying purchases.

Prerequisites and installation

The project README lists PHP 7.4–8.5 and a Chrome/Chromium executable at version 65 or later as requirements. It says the library is tested on Linux and compatible with macOS and Windows. These are project-stated requirements, not an independent compatibility guarantee; check the README and the release you install before relying on them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Install Composer if it is not already available in your project.
  2. From the project directory, install the browser-control library: composer require chrome-php/chrome.
  3. Install Chrome or Chromium for the operating system where PHP will run, and make sure the executable is available to the PHP process. If it is not on the usual path, configure the executable path using the options supported by the version of the library you installed.

Guzzle is optional for the screenshot itself. If the application separately needs Guzzle, install it with composer require guzzlehttp/guzzle; it will not replace Chrome in the capture flow.

Runnable PHP example: capture a page and save a PNG

This example follows the library’s BrowserFactory, navigation wait, screenshot and cleanup pattern. Replace the example URL and output path as needed. The default screenshot format is PNG.

<?php

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

use HeadlessChromiumBrowserFactory;

$url = 'https://example.com';
$outputPath = __DIR__ . '/screenshot.png';

$browserFactory = new BrowserFactory();
$browser = $browserFactory->createBrowser();

try {
    $page = $browser->createPage();
    $page->navigate($url)->waitForNavigation();
    $page->screenshot()->saveToFile($outputPath);
} finally {
    $browser->close();
}

printf("Saved screenshot to %s\n", $outputPath);

The call to waitForNavigation() waits for navigation to complete before the capture is requested. It does not guarantee that every website-specific asynchronous widget, image, or late-loading element has finished; for those cases, use the wait or page-interaction features documented for the library version in use.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Choose the capture area and image format

The library documents PNG by default and also supports JPEG and WebP. It distinguishes among the visible viewport, a clipped region, and the whole page. Set the viewport deliberately when the dimensions of the captured browser window affect the result. For whole-page output, the project documents using getFullPageClip with captureBeyondViewport; consult the project documentation for the exact options and method signatures of your installed release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Viewport: captures the currently visible browser area. Choose this when the screenshot should match a particular window or device-sized view.
  • Clipped region: captures a selected rectangle rather than the complete viewport. Use it when only a known portion of the page matters.
  • Full page: captures beyond the initial viewport to include the page’s longer content. Very long pages can produce large image files and may take more time or memory than a viewport capture.
  • Format: use PNG for the documented default; JPEG or WebP may suit workflows that expect those formats. Confirm the method’s format options against the library release you have installed.

Where Guzzle belongs

Use Guzzle for ordinary HTTP work such as calling an API or retrieving a resource. A browser screenshot is different: Chrome must load and render the page, including browser-side layout and scripts, before the image can be captured. The screenshot example above therefore calls the Chrome-control library rather than making a Guzzle request.

Guzzle can use handlers other than cURL, including PHP’s stream wrapper, according to its FAQ. Handler choice depends on the task and installed Guzzle version. Do not assume that every handler supports the same concurrency behavior: Guzzle’s overview notes cURL is required for concurrent requests. That transport detail applies to Guzzle HTTP requests, not to Chrome’s page rendering.

Or skip the browser setup

ScreenshotNeo offers a screenshot API and MCP server for developers. Send one GET request to capture a URL; it returns an image or PDF. Cookie banners, newsletter popups and chat widgets are removed before capture, and each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed; response headers report the page verdict and billing status. AI agents can use its MCP tools for screenshots, page information and PDF capture.

One-call cURL example (see the ScreenshotNeo documentation for the API options):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Troubleshooting

  • Chrome or Chromium does not start: confirm the executable is installed and accessible to the PHP user. If it is installed in a nonstandard location, set the executable path using the configuration supported by your installed chrome-php/chrome release.
  • Composer reports a PHP constraint conflict: compare the PHP runtime used by Composer with the version range listed by the library release you intend to install. The project README’s stated range is PHP 7.4–8.5; check the current release requirements rather than assuming every version has the same constraints.
  • The screenshot is blank or incomplete: check that navigation succeeded and that the target page does not require additional time or interaction before rendering its content. Use a documented wait strategy appropriate to the page rather than assuming navigation completion means every asynchronous element is ready.
  • The image only includes the first screen: that is viewport capture behavior. Use the library’s documented full-page clip and beyond-viewport capture options if the entire document is required.
  • The output file is missing or unwritable: verify that the PHP process can write to the destination directory and that the path is correct. Use an absolute path while diagnosing path and permission issues.
  • Guzzle handler or concurrency expectations are wrong: treat Guzzle transport configuration separately from browser capture. Its FAQ describes stream-wrapper and other handlers; its overview says cURL is needed for concurrent requests. Verify the behavior for the Guzzle version and handler in your application.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reliability and operating considerations

Always close the browser in a finally block so cleanup runs if navigation or screenshot saving throws an exception. In production, also decide how the application will handle browser startup failures, navigation timeouts, output-file errors and retry policy; blindly retrying a slow or blocked page can consume more resources without producing a useful image. Pin and validate the dependency version and browser executable used in deployment, since browser automation compatibility can change over time.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.