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

Use page.screenshot() for image files and expect(page).toHaveScreenshot() for visual-regression assertions. Set fullPage: true for the entire scrollable document, clip for a rectangle, and mask for locator-selected regions. For repeatable output, disable animations, hide the caret, normalize dynamic content with capture styles, and choose css or device scale deliberately.

The two screenshot APIs

Saving an image with page.screenshot()

The Page API captures the current page and returns a buffer; supplying path also writes the file. The format is inferred from the filename extension unless you set type explicitly.

import { chromium } from 'playwright';

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

Comparing snapshots with Playwright Test

expect(page).toHaveScreenshot() is an assertion, not merely a file export. It captures repeatedly until two consecutive screenshots match, then compares the result with the stored baseline. It accepts the normal capture controls plus maxDiffPixels, maxDiffPixelRatio, and threshold.

import { test, expect } from '@playwright/test';

test('home page is stable', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('home.png', {
    animations: 'disabled',
    maxDiffPixelRatio: 0.01
  });
});

Defaults differ: direct page screenshots allow animations, while screenshot assertions disable them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Choose the capture area

Viewport screenshot (the default)

With no scope option, Playwright captures the currently visible viewport. This is useful for above-the-fold checks and fixed-size visual tests.

await page.screenshot({ path: 'viewport.webp', type: 'webp', quality: 82 });

Full scrollable page

fullPage: true captures the full scrollable document instead of only the viewport.

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

Very long pages can create very large images. If your baseline system or image viewer has size limits, prefer section captures or a PDF workflow.

Rectangular clipping

clip takes an object with x, y, width, and height. Coordinates are page coordinates, so obtain an element’s bounding box when the target is a DOM node.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const card = page.locator('[data-testid="pricing-card"]');
const box = await card.boundingBox();
if (!box) throw new Error('Pricing card is not visible');
await page.screenshot({ path: 'card.png', clip: box });

Handle a null bounding box: the element may be hidden, detached, or outside a state your test has reached.

Hide private or changing content

Locator masks

Pass locators in mask to cover their bounding boxes. This is appropriate for timestamps, account names, rotating adverts, or personal data. The default overlay is magenta; set maskColor (available from Playwright 1.35) to match your test convention.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
await page.screenshot({
  path: 'account.png',
  mask: [
    page.locator('[data-testid="user-name"]'),
    page.locator('.live-clock')
  ],
  maskColor: '#222222'
});

Masking is locator-based and covers the bounding box, including invisible elements. Build the locator so it selects only the intended visible instance; use visibility-aware selectors or filter the locator before passing it.

Normalize content with capture-time CSS

The style option injects stylesheet text during capture, piercing Shadow DOM and inner frames. It is available from Playwright 1.41. Use it to hide blinking indicators, freeze transitions, or replace unstable presentation without changing production code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'normalized.png',
  style: `
    *, *::before, *::after {
      animation: none !important;
      transition: none !important;
      caret-color: transparent !important;
    }
    .last-updated, .random-ad { visibility: hidden !important; }
  `
});

For assertions, use the equivalent stylesheet option (often called stylePath) to load a file containing these rules; the assertion documentation identifies that option as added in 1.41.

Make captures deterministic

Disable animations

Set animations: 'disabled' to stop CSS animations, CSS transitions, and Web Animations. Finite animations are fast-forwarded to completion; infinite animations are canceled to their initial state for the capture and then resumed afterward.

await page.screenshot({
  path: 'stable.png',
  animations: 'disabled',
  caret: 'hide'
});

Control the caret

caret: 'hide' (the default) prevents a blinking text cursor from changing pixels. Use caret: 'initial' only when the caret itself is part of what you are testing.

Wait for the state you actually need

Navigate with an appropriate readiness condition, then wait for a meaningful selector rather than relying only on a fixed delay.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="dashboard-ready"]').waitFor();
await page.screenshot({ path: 'dashboard.png', animations: 'disabled' });

A page that depends on late API data, fonts, or lazy images may still change after load. Wait for the application’s ready marker, or for the specific images and controls your test needs.

Scale, format, quality, and transparency

CSS pixels versus device pixels

scale: 'css' emits one output pixel per CSS pixel, producing smaller high-DPI images. scale: 'device' uses device pixels and is the default for page.screenshot(), preserving the resolution associated with the emulated device.

Option Result Use it when
css One image pixel per CSS pixel Baselines should stay compact and independent of high-DPI density
device Device-pixel resolution You need the sharper, higher-resolution rendering of the emulated device

PNG, JPEG, and WebP

Set type to png, jpeg, or webp. quality accepts 0–100 for JPEG and WebP and has no effect on PNG.

await page.screenshot({ path: 'photo.jpg', type: 'jpeg', quality: 80 });
await page.screenshot({ path: 'asset.webp', type: 'webp', quality: 85 });
await page.screenshot({ path: 'lossless.png', type: 'png' });

Transparent output

omitBackground: true removes the default white background and permits transparency for PNG or WebP. JPEG cannot carry this transparent-background behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'logo.webp',
  type: 'webp',
  omitBackground: true
});

Timeouts and cancellation

The screenshot timeout is the maximum time in milliseconds. For direct page screenshots the default is 0 (no timeout), so set one explicitly in CI if a hung page must fail promptly.

await page.screenshot({ path: 'ci.png', timeout: 15000 });

The signal option accepts an AbortSignal and is available from Playwright 1.62.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const controller = new AbortController();
setTimeout(() => controller.abort(), 10000);
await page.screenshot({ path: 'cancelable.png', signal: controller.signal });

Visual-regression options that are easy to miss

Difference thresholds

Use maxDiffPixels for an absolute pixel allowance, maxDiffPixelRatio for a proportion of the image, and threshold for per-pixel color sensitivity. Keep allowances narrowly tied to known rendering noise; a generous threshold can hide a real layout regression.

Assertion styles and baselines

Apply a shared stylesheet to hide clocks, ads, or caret effects before each assertion. Keep browser, viewport, device scale, fonts, and locale consistent across baseline and comparison runs. A changed Playwright version or browser engine can legitimately require new baselines.

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

Option selection by goal

Goal Recommended settings
Above-the-fold smoke image Default viewport, caret: 'hide', explicit readiness wait
Documentation of an entire article fullPage: true, disabled animations, a suitable image format
One component Element boundingBox() passed to clip
Privacy-safe account screenshot mask for names, balances, and timestamps
Small high-DPI baseline scale: 'css', PNG or WebP
Transparent asset omitBackground: true with PNG or WebP
Regression test toHaveScreenshot(), animations: 'disabled', controlled diff limits
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting Playwright screenshots

The image is only the visible viewport

Add fullPage: true. If you intended a component, calculate its bounding box and pass it as clip instead.

The screenshot is blank or missing content

Confirm navigation succeeded, wait for the application’s ready selector, and check that the element is not hidden behind a consent dialog or modal. For lazy-loaded pages, scroll or otherwise trigger the application’s loading behavior before capture.

Visual tests fail intermittently

Disable animations, hide the caret, mask changing data, and inject normalization CSS. Also standardize fonts, viewport, locale, timezone, and browser version in CI.

Masked pixels are pink

That is the default maskColor. Set a different color, such as #222222, when the baseline or downstream processing requires it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Transparency is not present

Use PNG or WebP with omitBackground: true; JPEG does not support this transparent-background behavior.

An option is rejected

Check the installed Playwright version. The documented additions are maskColor in 1.35, style/stylePath in 1.41, and signal in 1.62. Shared libraries and CI images often lag behind a developer workstation.

Performance, reliability, and cost considerations

Full-page captures and device-scale output consume more memory and produce larger files than viewport captures at CSS scale. Use clipping, CSS scale, WebP, or JPEG when fidelity requirements permit. For visual tests, deterministic waits and stable rendering usually save more CI time than increasing diff tolerances. The official API references define behavior and defaults but do not provide a benchmark number for screenshot performance.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF. Before capture it accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status.

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

cURL (see the ScreenshotNeo documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Features include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed links, asynchronous webhooks, bulk capture of 100 URLs per call, usage data, and an OpenAPI specification. Common screenshot-API parameter names are accepted to ease migration.

The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

Frequently Asked Questions

Can I combine fullPage and clip?

They express different scopes: full-page capture expands to the scrollable document, while clip selects a rectangle. For a specific region, calculate its bounding box and use clip; use fullPage when the whole document is required.

Does quality change PNG files?

No. Quality applies only to JPEG and WebP; PNG output ignores it.

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

Which Playwright version supports signal?

The option is documented as added in Playwright 1.62. Verify the version installed in the environment running your tests.

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.