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

Use Playwright’s page.screenshot() after navigating to the target URL. Launch Chromium with headless: true (the documented default), wait for the page state your capture needs, and save the result with a path or keep the returned buffer. Add fullPage: true for the entire scrollable page, or capture a locator when you need one element.

Install Playwright and a browser

These commands create a small Node.js project and install Playwright with its browser binaries:

mkdir playwright-shots
cd playwright-shots
npm init -y
npm install playwright
npx playwright install chromium

The examples below use Chromium. You can replace chromium with another Playwright browser when your project requires it. Run the script with node screenshot.js.

Take a basic screenshot in headless mode

Create screenshot.js with this complete script:

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

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });
  await browser.close();
})();

page.goto() loads the page, and page.screenshot() writes screenshot.png in the current directory. Headless mode runs without opening a visible browser window. Playwright’s BrowserType API documents headless mode as the default, but stating it explicitly makes scripts and deployment settings unambiguous.

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.

Wait for the page state you actually need

A navigation promise resolving does not guarantee that a late-rendered chart, font, or image is visible. Add a locator wait for the content that defines a usable capture:

await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="dashboard-ready"]').waitFor();
await page.screenshot({ path: 'dashboard.png' });

Use a selector that represents readiness rather than an arbitrary long delay. If the site has no reliable readiness marker, a short, deliberate delay can be used, but it is less deterministic than waiting for a specific element.

Choose what Playwright captures

Viewport screenshot

With no area option, Playwright captures the current viewport. Set the viewport before navigation when a particular layout matters:

const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto('https://example.com');
await page.screenshot({ path: 'viewport.png' });

This is usually the most reviewable artifact for a responsive breakpoint because its dimensions match what a user sees at that viewport.

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

Full-page screenshot

Set fullPage: true to capture the page’s full scrollable height:

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

Full-page images preserve one long document, which is useful for archiving or visual review, but they can become very tall and harder to inspect. If a page changes layout while scrolling or contains fixed overlays, compare the output carefully with a viewport capture.

One element

Use a locator’s screenshot method for a component such as a header, card, or chart:

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

Playwright scrolls the locator into view first. It does not reveal pixels covered by another element, and a scrollable element captures only the content currently visible inside that element rather than all of its internal scroll range.

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

Rectangle clipping

For a precise region in page coordinates, pass a clip rectangle:

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: 'region.png',
  clip: { x: 100, y: 120, width: 800, height: 500 }
});

Clipping is useful when the target is not a stable locator. Keep the rectangle inside the rendered page; a stale coordinate can produce the wrong region after a responsive layout change.

Control image format, scale, and appearance

Playwright infers the image type from a supplied filename extension. When no type can be inferred, PNG is the default. The supported screenshot types are PNG, JPEG, and WebP.

Setting Example Use it when
PNG path: 'shot.png' You need lossless output or transparency.
JPEG path: 'shot.jpg', quality: 80 You want a smaller lossy image; JPEG does not support transparency.
WebP path: 'shot.webp', quality: 80 You want a modern compressed format supported by your pipeline.
CSS scale scale: 'css' You want one image pixel per CSS pixel and a compact artifact.
Device scale scale: 'device' You need device-pixel detail, accepting a potentially larger file.

When saving JPEG or WebP, set quality to control lossy compression. The exact visual result depends on the page and the chosen quality value.

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.

Freeze motion for deterministic captures

Animations are allowed by default. Disable CSS animations, transitions, and Web Animations during capture when motion would make screenshots vary:

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

Playwright treats finite and infinite animations differently when disabling them, so verify that the resulting frame is the one your review or test expects. Disabling animation is a test aid, not a substitute for checking a real animation bug.

Transparent backgrounds

Use omitBackground: true when you need the page’s default background removed. This is intended for formats that support transparency; it does not apply to JPEG.

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

Mask dynamic regions

Mask locators that legitimately change, such as timestamps or rotating identifiers, so visual comparisons focus on stable layout:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'masked.png',
  mask: [page.locator('[data-testid="clock"]')]
});

Masking hides a known dynamic region; it should not hide a genuine layout regression. The screenshot API also supports injected screenshot styles when a temporary style rule is a better way to neutralize a component.

Save to a file or keep the image in memory

Passing path writes the image directly. Omitting path returns a buffer, which is useful for uploads, hashing, or sending the image to another service without creating a temporary file:

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.
const image = await page.screenshot({ type: 'png' });
await require('fs').promises.writeFile('buffer-shot.png', image);

If you provide both a path and processing logic, remember that the returned value is the captured bytes; your application can choose whether to persist, upload, or transform them.

Use screenshots in Playwright Test

Manual page.screenshot() calls are explicit workflow steps. Playwright Test can collect screenshots automatically as test artifacts with modes such as on, only-on-failure, and on-first-failure. It can also be configured for full-page screenshots. This test-runner configuration is separate from a manual screenshot call.

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

Automatic failure artifacts are convenient when you mainly need evidence of a failed test. A manual call is better when the screenshot is part of the test’s actual assertions, documentation, or a named output contract.

Make visual comparisons reliable

Rendering can vary with the host operating system, browser version, browser settings, hardware, power source, and headless mode. Generate and compare baselines in the same environment whenever possible. Keep the browser binary, viewport, device settings, and animation state consistent between baseline and comparison runs.

When a screenshot unexpectedly differs, check these variables in order:

  1. Confirm the browser and browser version used for both images.
  2. Compare viewport dimensions, device scale, and any emulated device settings.
  3. Check whether animations, transitions, caret blinking, or delayed content were active.
  4. Verify that fonts, images, and network data finished loading before capture.
  5. Mask only regions that are genuinely nondeterministic, and investigate every unmasked difference.

Playwright’s screenshot assertion waits for two consecutive screenshots to match before comparing against the expected image. That stability check helps with brief layout settling, but it cannot make two different environments identical.

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

Troubleshoot common failures

“Executable doesn’t exist” or browser launch failure

Cause: the Playwright package is installed but its browser binaries are missing, or the runtime user cannot access them.

Fix: run npx playwright install chromium in the same environment that runs the script. In a container or CI job, install browsers during the image build and verify filesystem permissions.

The screenshot is blank or captured before content appears

Cause: the page is still rendering client-side content, a required request failed, or the script captured immediately after navigation.

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

Fix: wait for a meaningful locator, inspect the page for an error state, and log navigation failures. Prefer a readiness selector over increasing a fixed timeout.

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.

Full-page output is unexpectedly short

Cause: the document has not expanded yet, content is inside a separate scrollable container, or lazy content requires an interaction or scroll.

Fix: wait for the content that defines the final height. If the content lives in a nested scroll area, capture that locator or scroll it deliberately; fullPage refers to the page’s scrollable document, not every nested container.

An element screenshot misses part of a panel

Cause: the locator points to a scrollable element, or another element covers the missing pixels.

Fix: capture the visible state after scrolling the panel to the required position, remove the covering overlay only when that reflects the intended test state, or use a different locator for the content you need.

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

Images differ between local and CI

Cause: OS, browser, hardware, power mode, viewport, device scale, fonts, or animation state differ.

Fix: standardize the execution image and browser, set the viewport explicitly, disable or control animation, and regenerate baselines only after confirming the change is intentional.

The file is too large

Cause: a full-page capture, device-pixel scale, or lossless format creates a large artifact.

Fix: capture the viewport or a component when full height is unnecessary, use scale: 'css', and choose JPEG or WebP with an appropriate quality value when lossless output is not required.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and operating cost

Browser startup is often the most expensive part of a one-off script. For batches, keep one browser process open and create separate pages or contexts as appropriate for isolation. Reuse a page only when shared state cannot contaminate the next capture. Set navigation and operation timeouts that match your site instead of allowing a job to hang indefinitely, and always close the browser in a finally block in production code.

Full-page images consume more memory than viewport images, especially at device scale. Limit concurrency when capturing many long pages, and stream or upload buffers promptly rather than retaining every image in memory. Treat screenshots as build artifacts: name them deterministically, record the URL and viewport that produced each file, and retain failed-run output long enough to diagnose the cause.

Playwright itself does not charge per screenshot; your costs come from the machine, CI minutes, browser storage, bandwidth, and any external service you add. A self-hosted browser gives control over environment and data, while a screenshot API can remove browser installation and maintenance from your workflow.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns a PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports the result in X-Page-Verdict and X-Billed headers.

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

Here is the one-call cURL form (see the ScreenshotNeo API documentation for all parameters):

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

The same request in 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)

And in 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}`);

ScreenshotNeo exposes 63 options, including full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets plus arbitrary viewports, retina scale, PDF paper size/margins/orientation/page ranges, HTML or CSS to image, custom JavaScript and CSS, pre-capture clicks, hidden selectors, waits for selectors/delays/network idle, ad/tracker/request/resource blocking, custom headers/cookies/user agents and Authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links for public <img> tags, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, an OpenAPI specification, and compatibility with parameter names used by other screenshot APIs.

Every feature is included on every plan. Pricing is:

Plan Included screenshots Price
Free 1,000 per month $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients, so an AI agent can capture pages without you wiring browser setup into each project.

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

Start with 1,000 free screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Frequently Asked Questions

Can I use a Playwright screenshot buffer without writing a temporary file?

Yes. Omit the path option; page.screenshot() returns the image bytes, which you can upload, hash, or pass to another function directly.

Why should visual baselines be generated in the same environment?

Playwright documents differences caused by the operating system, browser version, settings, hardware, power source, and headless mode. Keeping those variables consistent reduces environment-only diffs that are unrelated to your page.

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.