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 desk6 min

How to Capture a Webpage Screenshot with Playwright in Docker

A practical guide to running Playwright screenshots in Docker, from compatible image setup and capture modes to container flags and common fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Playwright in your container, launch Chromium, navigate to the page, and call page.screenshot(). The official Playwright Docker image supplies browser binaries and system dependencies, but you must install the Playwright package yourself and keep its version aligned with the image. For a viewport screenshot, save the image with page.screenshot({ path: 'screenshot.png' }); add fullPage: true to capture the full scrollable page.

Choose a Docker setup

You can start from the official Playwright image or build a Node.js image and install Playwright’s browsers and system dependencies in it. The official image does not include the Playwright package. In either case, pin compatible versions: browser binaries are tied to Playwright versions, and a mismatch can stop Playwright from finding its browser executable. See the official Docker guide and browser installation guidance.

As an Amazon Associate I earn from qualifying purchases.

Use the official Playwright image

Choose a specific image tag rather than latest, then install the matching Playwright package in your project. Check the current tags and use the same Playwright version for the package and image; tags can change over time.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm init -y
npm install playwright

Create a file named screenshot.js with the capture script below. Replace mcr.microsoft.com/playwright:v1.63.0-noble with the exact compatible tag you intend to use if it differs.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
FROM mcr.microsoft.com/playwright:v1.63.0-noble
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY screenshot.js ./
CMD ["node", "screenshot.js"]

The version shown is an example tag, not a guarantee that it remains current. Verify the available tags and package version when setting up the build.

Build from a Node.js image

Alternatively, use a Node.js base image and install Chromium and its system dependencies with Playwright’s CLI. The browser install command should use the same Playwright package version installed by npm.

FROM node:22-bookworm
WORKDIR /app
COPY package*.json ./
RUN npm ci && npx playwright install --with-deps chromium
COPY screenshot.js ./
CMD ["node", "screenshot.js"]

For a repeatable build, pin the Node.js base image and lockfile as well. If you upgrade Playwright, rerun the browser installation step so the browser binaries match the package.

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

Capture a viewport, full page, or element

This standalone Node.js example opens a page, waits for navigation to finish, saves a viewport screenshot, and closes the browser even if navigation or capture fails. Set the target URL and output filename for your use case.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
const { chromium } = require('playwright');

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

By default, the capture covers the current viewport. To capture the whole scrollable page, change the screenshot call to:

await page.screenshot({ path: 'screenshot.png', fullPage: true });

To capture only one element, use a locator. For example, after navigating:

await page.locator('main').screenshot({ path: 'main.png' });

Playwright can also return the screenshot as a buffer instead of writing a file. This is useful when the next step uploads or processes the image in memory:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const image = await page.screenshot();

Build and run the container

With the Dockerfile and script in the same directory, build and run the image. Mount an output directory so the screenshot remains available on the host after the container exits.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
docker build -t playwright-shot .
mkdir -p output
docker run --rm --init --ipc=host -v "$PWD/output:/app/output" playwright-shot

For this mount to work, set the screenshot path in your script to /app/output/screenshot.png. The --init flag helps avoid process-management issues such as zombie processes. The Playwright Docker guide recommends --ipc=host for Chromium because insufficient shared memory can cause it to run out of memory and crash.

Choose image dimensions and format deliberately

A viewport screenshot captures only what fits in the configured viewport; full-page mode extends the capture to the scrollable page, and locator screenshots isolate an element. You can configure viewport dimensions when creating a page, and use device presets or device scale settings where needed. The output path’s extension determines the image type; Playwright supports PNG, JPEG, and WebP screenshot output. Device-pixel scaling can produce larger files on high-density displays than CSS-pixel scaling. See the screenshot documentation.

For pages with lazy-loaded images, a full-page option alone may not ensure every image has loaded before capture. If completeness matters, scroll through the page or wait for the specific content you need before saving the image.

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

Make visual captures reproducible

Visual output can vary between environments. Playwright identifies host operating system, browser version, settings, hardware, power source, and headless mode as factors that can affect rendering. For visual regression checks, create and compare screenshots in a consistent environment, and use Playwright’s screenshot assertions to establish and check baselines. See visual comparisons.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Run browsers with appropriate container security

The official Playwright Docker setup’s default root-user configuration disables Chromium’s sandbox. The Docker guide describes the image as intended for testing and development; do not treat the default root configuration as a safe way to visit untrusted sites. For scraping or crawling untrusted pages, follow the guide’s separate-user and seccomp-profile approach, including the user namespace operations the browser requires. Review the Docker security guidance before exposing a browser container to untrusted input.

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

Troubleshoot common Docker capture failures

Playwright cannot find Chromium

Cause: The package version and image/browser version do not match, or the browser was not installed in a custom image. Fix: Align the Playwright package with the pinned image tag, or run npx playwright install --with-deps chromium during the custom image build.

Chromium crashes or exits unexpectedly

Cause: The container may have insufficient shared memory or process-management problems. Fix: Run with --ipc=host and --init, as recommended by the Playwright Docker guide.

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

The image file is missing on the host

Cause: The script wrote the image inside the container’s filesystem, which disappears when a removed container exits. Fix: Save to the mounted directory, such as /app/output/screenshot.png, and verify that the host directory is mounted at /app/output.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

The capture is blank or incomplete

Cause: The page may not have finished loading, or content such as lazy images may not yet have appeared. Fix: Wait for the relevant page state or selector before capturing; for lazy-loaded content, scroll through the page before taking a full-page screenshot.

Snapshots differ between runs or machines

Cause: Rendering conditions differ, including browser version, operating system, settings, or headless environment. Fix: Pin the container and Playwright versions and run baseline creation and comparisons in the same environment.

Or skip the browser setup

For an API-based capture, one GET request returns a screenshot. Create a ScreenshotNeo API key, then run:

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 API documentation. ScreenshotNeo accepts cookie banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and whether the shot was billed. Its MCP server lets AI agents use screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.

Frequently Asked Questions

Can I capture a page without saving a local file?

Yes. Call page.screenshot() without a path option to receive an image buffer.

Why does the official Playwright image still need an npm install?

The image includes browser binaries and system dependencies, but the Playwright package must be installed separately in your Node.js project.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.