October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober 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

How to Take Puppeteer Screenshots in a Docker Container

Use Puppeteer’s official Docker image to capture a page, with the right sandbox capability, init process, screenshot options and troubleshooting steps.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The most reproducible starting point is Puppeteer’s official Docker image: it includes Chrome for Testing and its required dependencies. Run it with an init process and the documented SYS_ADMIN capability so Chrome can remain sandboxed, then use Puppeteer’s page.screenshot() method to save the image.

Run Puppeteer in Docker with the official image

Puppeteer’s Docker guide documents an image hosted at GitHub Container Registry that includes Chrome for Testing, required dependencies and a pre-installed Puppeteer version. The example below uses the mutable latest tag for convenience; for repeatable builds, choose a version-specific image tag and keep Puppeteer aligned with its managed browser.

As an Amazon Associate I earn from qualifying purchases.

1. Create the screenshot script

Save this as screenshot.js:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });
    await page.screenshot({ path: '/output/page.png', fullPage: true });
  } finally {
    await browser.close();
  }
})();

The finally block closes Chrome even if navigation or capture fails. networkidle2 waits for network activity to settle to the threshold defined by Puppeteer; pages with continuous requests may not reach it promptly, so choose a different navigation condition or explicit wait when that better matches the page.

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

2. Run the container

From the directory containing screenshot.js, run:

mkdir -p output
docker run --rm -i --init --cap-add=SYS_ADMIN 
  -v "$PWD:/work" -v "$PWD/output:/output" -w /work 
  ghcr.io/puppeteer/puppeteer:latest node screenshot.js

The script reads from the mounted working directory and writes the PNG to output/page.png on the host. The output directory must be writable by the container user. The official image guide documents the sandboxed setup and SYS_ADMIN requirement; --init helps manage browser child processes.

#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C

Choose the screenshot output you need

Puppeteer’s screenshot API supports a viewport capture by default, a full-page image, a clipped region, and an element capture. See the screenshot guide and ScreenshotOptions reference for the supported options.

  • Viewport: omit fullPage to capture the visible page area.
  • Full page: set fullPage: true, as in the runnable example.
  • Clipped region: provide a clip rectangle to capture a specific area.
  • One element: locate it and call ElementHandle.screenshot().
  • Format: with a path, Puppeteer infers the format from the extension. PNG is the default; quality does not apply to PNG.
  • Transparency: screenshot options include a transparent-background setting for captures that need it.

For an element capture, the core pattern is:

const element = await page.$('main h1');
if (!element) throw new Error('Target element not found');
await element.screenshot({ path: '/output/heading.png' });

Build a custom image instead of using the official image

A custom base image gives you control over the operating-system packages and application layout, but you must supply a compatible Chrome installation and its shared libraries, and ensure Puppeteer can find the browser it is configured to use. Puppeteer warns that Chrome does not support Alpine out of the box; use a compatible base image rather than assuming an Alpine recipe will work. Package names and versions change, so validate dependencies against the current base image instead of copying old Dockerfile pins without checking them.

For repeatable output, pin the Puppeteer and browser versions together. Puppeteer’s official image offers version-specific tags; latest can change over time. If you install or cache the browser separately, verify that the package and browser are both present in the runtime image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model | External Solid State Drive, IP65 Water & Dust Resistant, Up to 3M Drop Protection, 256-bit AES Encryption, USB-C 3.2 Gen 2
  • NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
  • IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
  • POCKET-SIZED – fits easily in pockets and small bags.
  • SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
  • 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.

Keep Chrome sandboxed

Do not treat --no-sandbox as the routine fix for a Chrome launch error. The official Puppeteer image is intended to run Chrome in sandbox mode and documents the SYS_ADMIN capability for that setup. Puppeteer’s troubleshooting guide says running without a sandbox is strongly discouraged and should be considered only when the content is absolutely trusted. Disabling the sandbox weakens browser isolation, particularly when navigating to pages you do not control.

Troubleshoot common Docker failures

“Could not find expected browser locally” or a missing executable

Check that the Puppeteer package and browser installation are present in the image that actually runs the script. Puppeteer’s troubleshooting guide says that from version 19 the browser cache defaults to ~/.cache/puppeteer; set PUPPETEER_CACHE_DIR if you need to relocate that cache, and make sure the path is populated and readable at runtime.

“No usable sandbox!”

Use a supported sandbox configuration. With the official image, follow its documented sandbox setup and include --cap-add=SYS_ADMIN in the Docker run command. Avoid switching straight to --no-sandbox; Puppeteer documents that as a discouraged workaround for absolutely trusted content only.

Rank #3
SSK Portable SSD 250GB External Solid State Hard Drive USB C Up to 1050MB/s
  • Capacity Display Variance: 250GB external ssd often appears as around 232GB on Windows. MacOS can show full 250 GB capacity. This is binary calculation difference and doesn’t affect SSD hard drive actual physical storage
  • 1050 MB/s Speed: Instantly access to your files with blazing-fast 10Gbps external SSD read up to 1050MB/s and write up to 1000MB/s. LED Light indicates USB SSD instant activity
  • Data Security: Solid state drives S.M.A.R.T. health diagnostics​ and adaptive TRIM optimizing data block management ensures consistent write speeds and extends the longevity of the portable SSD
  • USB-C & USB-A Cable: Both cables featuring rapid USB 3.2 Gen2, this USB SSD effortlessly bridges devices, enabling seamless cross-platform file transfers and backup between computers, smartphones, tablets and iPhone
  • Always Fast: No slowdowns for large file transfers. With SLC caching (25% of current available capacity allocated as high-speed cache), this external SSD delivers steady 10Gbps for transfers within the cache capacity

chrome_crashpad_handler: --database is required or Chrome fails before connecting

Chrome needs writable profile, configuration and cache locations. In a read-only container, point XDG_CONFIG_HOME and XDG_CACHE_HOME to writable directories such as /tmp, and set Puppeteer’s userDataDir to a writable location if needed. Alternatively, mount writable directories with permissions suitable for the Chrome user.

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

Missing shared libraries or an incompatible base image

Chrome depends on system libraries. Use a compatible base and install the required dependencies; Puppeteer specifically warns that Chrome does not support Alpine out of the box. Validate the completed image rather than assuming a Dockerfile built for another base or an older package set will work unchanged.

Chrome processes linger after the job

Run the container with --init or use a suitable custom entrypoint so child processes are managed. Puppeteer’s troubleshooting guide notes that dumb-init may help with lingering Chrome processes in some setups.

Rank #4
Sale
Verbatim Pocket 512GB External SSD USB 3.2 Gen 2 Up to 1000MB/s
  • SMALL DRIVE. POWERHOUSE PERFORMANCE: The Verbatim Pocket SSD delivers high-speed storage in an ultracompact design built for creators, gamers, travelers, and everyday backup.
  • COMPACT AND CONVENIENT: Ultra-lightweight and small enough to slip into your back pocket, with a convenient keyring and cable holder to keep your cable neat and tangle-free
  • HIGH-SPEED READ AND WRITE PERFORMANCE: Read speeds up to 1000MB/s and write speeds up to 1000MB/s help you transfer files, back up content, and access media faster
  • RELIABLE SSD PERFORMANCE: Durable solid-state storage with no moving parts for dependable everyday use and improved energy efficiency
  • USB-C COMPATIBILITY: Connects easily to USB-C PCs, Macs, tablets, smartphones, gaming consoles, and more.

Screenshot work is slow on Cloud Run

Puppeteer’s troubleshooting page explains that Cloud Run disables CPU by default after an HTTP response is written. If browser work begins after the response is sent, it can appear unusually slow; complete the browser work before responding or configure always-allocated CPU where appropriate.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot endpoint rather than a browser container to maintain, ScreenshotNeo returns a screenshot or PDF from one GET request. For example, this cURL command saves a WebP capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for API options. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server lets AI agents use screenshot and PDF capture tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

Frequently Asked Questions

Where does the Docker command save the screenshot?

It saves the file on the host at output/page.png, through the mounted /output directory.

Best Value
SSK 128GB Portable SSD External Hard Drive Solid State Drive up to 550MB/s
  • Capacity Reminder: Display capacity of 128GB SSD often appears as around 116GB on Windows. MacOS typically shows full 128GB. This display capacity reduction of 7% to 10% from SSD actual capacity is from algorithms differences in which 1GB is interpreted as 1024MB on Windows and 1000MB on SSDs
  • 550MB/s: Instantly access to your files with blazing 6Gbps external ssd speed up to 550MB/s. LED Light indicates portable ssd instant activity (Actual speed depends on drive capacity, host device, OS and application)
  • Data Security: Master external solid state drives health with S.M.A.R.T. monitoring. TRIM technology ensures consistent write speeds and extends the longevity of the portable SSD
  • USB C+A : Both USB-C cable and USB-A adapter featuring rapid USB 3.2 Gen2, this USB SSD effortlessly bridges devices, enabling seamless cross-platform file transfers between computers, smartphones, tablets and Phones
  • Always Fast: No slowdowns during large file transfers. This external ssd remains steady 6Gbps by using high speed SLC caching (25%of the current available capacity is allocated for high speed cache)

Does Puppeteer take PNG screenshots by default?

Yes. PNG is the default, and when you provide a path the extension determines the output format.

Can I use this setup for pages that require authentication?

Yes, if you configure the page and browser context to authenticate before capture; the example itself does not log in or provide credentials.

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

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.