Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 Now×
Skip to content
World desk2 min

How to Take a Playwright Screenshot in Headless Chromium

A practical guide to capturing, saving, and stabilizing screenshots with Playwright in headless Chromium.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Launch Playwright’s Chromium browser, navigate to a page, then call page.screenshot(). Chromium runs headlessly by default, so a basic capture needs no special headless flag.

Capture a page with Playwright and Chromium

Install Playwright and its Chromium browser, then save a screenshot with this runnable JavaScript example:

As an Amazon Associate I earn from qualifying purchases.

const { chromium } = require('playwright');

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

Save it as screenshot.js and run node screenshot.js. The resulting screenshot.png is a viewport capture. The essential call is await page.screenshot({ path: 'screenshot.png' });; the surrounding steps launch Chromium, open a page, and navigate to the URL. See Playwright’s Page screenshot API and browser documentation.

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

Install the browser if needed

Install the Playwright package in your project and install its browser binaries. For headless-shell-only installations, Playwright documents npx playwright install --with-deps --only-shell. Browser build and installation details can change between Playwright releases; consult the browser documentation for the version installed in your project.

#1 Best Overall
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.

Choose viewport or full-page capture

By default, the screenshot contains the current viewport, not the entire scrollable document. Set fullPage: true to capture the full page:

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

Use viewport capture when you need the visible screen at a specific point in a page. Use full-page capture for a long document or page overview. Full-page output can be substantially taller than a viewport image.

Rank #2
Samsung 27" Odyssey G5 (G51F) Series QHD (1440P) Gaming Monitor | 180Hz, 1ms, AMD FreeSync, HDR10, Height Adj Stand, Black Equalizer, Virtual Aim Point, Auto Source Switch+ (LS27FG512ENXZA)
  • QHD Resolution (2560 x 1440) has 1.7 times the pixel density of Full HD for incredibly detailed pinsharp images
  • HDR10 provides brighter highlights and nuanced shadow for added depth - making every scene feel more vivid and realistic
  • The 180Hz refresh rate minimizes lag for gameplay with ultra-smooth action. Plus, the 1ms response time helps capture your moves in real-time, allowing you to react fast for gaming precision
  • AMD FreeSync reduces choppiness, screen lag and image tearing, ensuring that your fast-paced, complex in-game action is stable with minimal stutter
  • Ergonomic stand allows for tilt, pivot and height adjustments to maximize gaming comfort

Control output format, quality, and scale

Playwright supports PNG, JPEG, and WebP screenshots. PNG is the default; when saving to a path, Playwright can infer the format from the filename extension.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • PNG: Default format. The quality setting does not apply.
  • JPEG: Specify type: 'jpeg' and optionally a quality value. The documented default quality is 80.
  • WebP: Specify type: 'webp' and optionally a quality value. The documented default is 100, which is lossless.
await page.screenshot({
  path: 'page.webp',
  type: 'webp',
  quality: 85,
  scale: 'css'
});

scale: 'css' creates one image pixel per CSS pixel. scale: 'device' uses device pixels and may create larger, high-DPI images; it is the documented default. Pick the scale according to whether the output should match CSS layout dimensions or retain device-pixel detail.

Rank #3
Dell 27 240Hz Gaming Monitor - SE2726HG - 27-inch FHD (1920x1080) Display, in-Plane Switching (IPS) Technology, AMD FreeSync Premium, TÜV 3-Star, 2X HDMI, DisplayPort 1.4, Tilt
  • Smooth motion: 240Hz refresh rate and fast 0.5ms response time provide crisp visuals and fluid movement with less input lag.
  • Seamless gaming: FreeSync Premium and HDMI VRR eliminate tearing for smooth, responsive PC and console gameplay.
  • Fast IPS: Faster 0.5ms response with excellent color accuracy across wide IPS viewing angles.
  • Rich color: 99% sRGB color coverage delivers vivid, detailed imagery with strong accuracy.
  • Eye comfort: TÜV Rheinland 3‑star certified display lowers blue light while preserving color quality.

Save the image or use it in memory

Providing path writes the image to disk. Without path, page.screenshot() returns an image buffer instead:

const image = await page.screenshot();
// Pass image to code that accepts a Buffer, or write it yourself.

This is useful when a script needs to upload the image, attach it to a report, or process it without first choosing a screenshot path in the API call.

Rank #4
Sale
SANSUI 27 Inch Curved 240Hz Gaming Monitor FHD 1080P, 1500R Curve Computer Monitor, 130% sRGB, 4000:1 Contrast, HDR, FreeSync, MPRT 1Ms, Low Blue Light, HDMI DP Ports, Metal Stand, Cable Incl.
  • 27” 240Hz 1500R Curved FHD 1080P Gaming Monitor for Game Play.
  • Prioritizes Gaming Performance: Up to 240Hz high refresh rate, more immersive 1500R Curvature, FreeSync, MPRT 1ms Response Time, Black Level adjustment(shadow booster), Game Modes Preset, Crosshair.
  • Cinematic Color Accuracy: 130% sRGB & DCI-P3 95% color gamut, 4000:1 contrast ratio, 300nits brightness, HDR, Anti-flicker; Anti-Glare.
  • Plug & Play Design: HDMI & DP1.4 & Audio Jack(No built-in speakers), durable metal stand, tilt -5°~15, VESA 100*100mm compatible.
  • Warranty: Money-back and free replacement within 30 days, 1-year quality warranty and lifetime technical support. Pls contact SANSUI service support first if any product problem.

Make captures more repeatable

For stable captures, reduce movement and control the browser environment. The screenshot API offers animations: 'disabled' to disable CSS animations, transitions, and Web Animations during capture. Finite animations are fast-forwarded; infinite animations are canceled to their initial state for the screenshot. Playwright resumes animations afterward.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'stable.png',
  animations: 'disabled',
  style: '*, *::before, *::after { caret-color: transparent !important; }'
});

The optional style value injects CSS for the capture, letting you hide or alter dynamic content when appropriate. Screenshots can still differ across operating systems, browser versions, settings, hardware, power sources, and headless modes. For visual baselines, create and compare images in the same environment. Playwright explains these sources of variation in its visual comparisons guide.

Best Value
Sale
Sceptre Curved 24-inch Gaming Monitor 1080p R1500 98% sRGB HDMI x2 VGA Build-in Speakers, VESA Wall Mount Machine Black (C248W-1920RN Series)
  • 1800R curve monitor the curved display delivers a revolutionary visual experience with a leading 1800R screen curvature as the images appear to wrap around you for an in depth, immersive experience
  • Hdmi, VGA & PC audio in ports
  • High refresh rate 75Hz.Brightness (cd/m²):250 cd/m2
  • Vesa wall mount ready; Lamp Life: 30,000+ Hours
  • Windows 10 Sceptre Monitors are fully compatible with Windows 10, the most recent operating System available on PCs.Brightness: 220 cd/M2
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Direct screenshots versus visual assertions

Use page.screenshot() when you need an image file or buffer. For automated visual regression tests, Playwright Test provides expect(page).toHaveScreenshot(). It waits until two consecutive screenshots match and then compares the result with an expected snapshot. Screenshot assertions are for the Playwright Test runner, rather than a replacement for the ordinary screenshot API.

Common problems and fixes

  • No image appears on disk: Check that the script reached the screenshot call and that the process has permission to write to the selected directory. Use an explicit path if the current working directory is unclear.
  • Only the visible area is captured: This is the default. Pass fullPage: true to capture the full scrollable page.
  • The screenshot looks soft or is unexpectedly large: Check the scale option. The default device scale uses device pixels; css gives one output pixel per CSS pixel.
  • Output format or quality is unexpected: Confirm the path extension or set type explicitly. Quality affects JPEG and WebP, not PNG.
  • Captures differ between runs or machines: Disable animations when appropriate and keep the operating system, Playwright/browser version, settings, and execution environment consistent.
  • Chromium is missing or the requested installation is too large: Install the browser build required by your Playwright version. The documented headless-shell-only command is npx playwright install --with-deps --only-shell; check the browser docs before choosing an installation mode.

Or skip the browser setup

For a one-request screenshot without managing Playwright or Chromium, ScreenshotNeo accepts a URL and returns an image or PDF. Its screenshot API can remove cookie and consent banners, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents.

Example cURL request (see the ScreenshotNeo API documentation):

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

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free.

Frequently Asked Questions

Does Playwright launch Chromium headlessly by default?

Yes. Playwright documents Chromium as headless by default. Its regular Chromium build and headless shell are separate options, and browser behavior can vary by Playwright release.

Can I get a screenshot without writing a file?

Yes. Omit the path option; page.screenshot() returns a buffer.

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.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.