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

Use await page.screenshot({ path: 'screenshot.png' }) to save the current browser viewport as an image in Playwright. Add fullPage: true for the full scrollable page, or call screenshot() on a Locator to capture one element. For repeatable visual checks, use Playwright Test’s toHaveScreenshot() assertion and control animations and dynamic content.

Set up a TypeScript screenshot

Install Playwright in your project, then create a TypeScript file such as screenshot.ts. This example launches Chromium, opens a page, saves a PNG, and closes the browser:

import { chromium } from 'playwright';

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

main();

Run the file using the TypeScript runner or build setup already used by your project. The try/finally ensures the browser is closed even if navigation or capture throws an error. Playwright’s screenshot call is asynchronous, so await it before closing the browser.

The path option writes the image to disk. A relative path is resolved from the current working directory, and Playwright infers the image format from the filename extension. Without path, page.screenshot() returns image bytes, which you can pass to another function or write yourself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
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

Choose what to capture

Current viewport

The basic page.screenshot() call captures the page’s visible viewport. Set the viewport size before navigating or capturing when you need consistent dimensions:

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

Full scrollable page

Use fullPage: true to capture beyond the currently visible viewport, extending to the page’s full scrollable height. The option defaults to false.

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

A full-page capture can be much taller and larger than a viewport image. If the page has content that appears only after scrolling, verify that the site has loaded it before capturing; a full-page option is not a substitute for waiting for lazy-loaded content to become available.

One element

Call screenshot() on a Locator to capture the element’s bounding box rather than the entire viewport. Locators also wait for the target to become actionable under Playwright’s locator behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('.header').screenshot({ path: 'header.png' });

Use a selector that identifies the intended element uniquely. If it is not present, is hidden, or resolves ambiguously for your intended capture, adjust the selector or wait for the page state that makes the element visible.

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

One rectangular region

Use clip when you need a coordinate-based rectangle rather than a DOM element. Its object takes x, y, width, and height:

await page.screenshot({
  path: 'region.png',
  clip: { x: 40, y: 80, width: 500, height: 300 },
});

Coordinates describe a region in the page screenshot context. Prefer a Locator capture for a component whose position may move as the layout changes; a fixed clip can cut off the target if page geometry shifts.

Set output and image options

Playwright supports PNG, JPEG, and WebP screenshot types. You can set type explicitly; otherwise the path extension determines the type. The quality option applies to JPEG and WebP, not PNG.

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.
await page.screenshot({
  path: 'compressed.webp',
  type: 'webp',
  quality: 80,
});

Choose PNG when you need lossless output, such as pixel-sensitive comparisons. JPEG or WebP can reduce image size at the cost of lossy compression, so avoid comparing their output to a baseline generated with different encoding settings.

By default, screenshots use device pixels. Set scale: 'css' for one output pixel per CSS pixel; use scale: 'device' when you want device-pixel dimensions and higher-density output. Keep the scale consistent across captures intended for direct comparison.

Rank #3
Sale
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.

For a transparent background, set omitBackground: true. This is not applicable to JPEG, which does not support transparency.

Make captures more predictable

Disable motion

Animations and transitions can make captures vary from run to run. Set animations: 'disabled' to disable CSS animations, CSS transitions, and Web Animations during capture. Finite animations are fast-forwarded; infinite animations are canceled for the capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'still.png',
  animations: 'disabled',
});

This controls animation-related variation, not every source of change. Data, timestamps, rotating content, or third-party widgets may still differ between runs.

Mask changing regions

Use mask to cover selected Locator bounding boxes, such as a live timestamp or avatar that changes between runs. The default mask color is pink, #FF00FF; set maskColor to choose another color.

await page.screenshot({
  path: 'masked.png',
  mask: [page.locator('[data-testid="live-time"]')],
  maskColor: '#222222',
});

Masking hides the selected area in the output; it does not make the underlying page data deterministic. Choose masks narrowly so real layout or rendering regressions remain visible.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

Wait for the state you intend to capture

Navigate to the page and wait for the relevant content or application state before taking the screenshot. For a specific element, a Locator wait is often more reliable than an arbitrary sleep:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.goto('https://example.com');
await page.locator('main h1').waitFor({ state: 'visible' });
await page.screenshot({ path: 'ready.png' });

Waiting for an element confirms that it is visible, not that every image, font, or remote service has completed loading. If the subject of the capture depends on a particular resource or UI state, wait for that condition directly.

Use Playwright Test for visual regression

For a maintained baseline comparison, use Playwright Test’s screenshot assertion rather than manually comparing files:

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

test('homepage matches the baseline', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('homepage.png');
});

Screenshot assertions are supported by the Playwright Test runner; they are not a general-purpose assertion feature for arbitrary scripts. On the first run, the runner creates a baseline when configured to do so; subsequent runs compare against it. Review and commit intended baseline updates rather than automatically accepting every visual difference.

The assertion waits for two consecutive screenshots to match before comparing with the expectation, which helps avoid comparing while a page is still changing. Its options include full-page capture, masking, animation control, thresholds, and maximum differing pixels. Use those options to reflect the actual purpose of the test: masking known volatile content can reduce noise, while permissive thresholds can also hide small genuine changes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Capture without writing a file

When you omit path, the screenshot call returns a buffer. This is useful when the next step uploads an image, stores it in object storage, or processes it in memory:

const image = await page.screenshot({ type: 'png' });
await processImage(image);

The example assumes your project defines processImage. If you need a local file instead, pass a path to Playwright or write the returned bytes using your runtime’s filesystem APIs.

Common screenshot problems

  • The file is not where expected: A relative path is relative to the process’s current working directory, which may differ from the directory containing the TypeScript file. Use an absolute path or inspect the working directory.
  • The image is only the visible portion: The default is viewport capture. Add fullPage: true to capture the scrollable page, or use a Locator screenshot for a single element.
  • The element capture fails or shows no target: Check that the selector matches the live page, the element is visible, and the application has reached the state where it appears. Wait for the specific Locator before capturing.
  • Visual tests fail intermittently: Disable animations, mask genuinely variable regions, use a stable viewport and scale, and wait for the content under test. Do not mask areas whose appearance is what the test is meant to verify.
  • The screenshot is unexpectedly large: Full-page height and device-pixel scale can increase output dimensions. Capture only the needed scope or use CSS-pixel scale when that resolution meets your use case.
  • Transparent output is missing: Use a format with alpha support, such as PNG, together with omitBackground: true; JPEG cannot preserve transparency.
  • The saved image is lossy: Check the selected type and quality. Use PNG for lossless output, and keep encoding settings the same when generating visual baselines.

Or skip the browser setup

For a one-request screenshot rather than a Playwright browser flow, ScreenshotNeo returns an image or PDF from a URL. Here is the cURL version; the API documentation is at ScreenshotNeo’s API docs.

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

ScreenshotNeo accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and whether the shot was billed. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is on every plan.

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.

Sign up free for 1,000 screenshots a month with no card.

Choose the right capture method

  • Use page.screenshot() for a viewport image or returned image bytes.
  • Use fullPage: true when the entire scrollable document belongs in the image.
  • Use locator.screenshot() when the subject is one page element.
  • Use expect(page).toHaveScreenshot() inside Playwright Test when you need a baseline-based visual regression assertion.

Frequently Asked Questions

Can I take a screenshot in Playwright without saving it to disk?

Yes. Call page.screenshot() without a path; it returns image bytes.

Can Playwright screenshot assertions run in a standalone script?

No. The toHaveScreenshot() screenshot assertion is for the Playwright Test runner.

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.