Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To take a screenshot with Playwright, navigate to the page and call await page.screenshot({ path: 'screenshot.png' }). That saves the current viewport to a file. Set fullPage: true to capture the scrollable page, use clip for a rectangle, or call screenshot() on a locator to capture one element. The examples below use Playwright’s JavaScript API; the same capture choices are available in its other language bindings, though their syntax differs.
Capture a page with Playwright
A Playwright screenshot is an image of a browser page at the time the screenshot call runs. The smallest useful example creates a browser, opens a page, navigates to a URL, saves the screenshot, and then closes the browser. This version uses WebKit, as in the official Playwright example; Chromium and Firefox can also be used.
const { webkit } = require('playwright');
(async () => {
const browser = await webkit.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
Save the file as screenshot.js and run it with node screenshot.js in an environment where Playwright and its browser are installed. The important operation is page.screenshot(); the browser setup makes the example runnable as a standalone script. In an existing Playwright script or test, use the same call with the page you already created.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →If you pass a path, Playwright writes the image there. If you omit path, the call returns screenshot data instead, which can be processed in memory or passed to another function without first writing a file:
#1 Best Overall
- 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
const image = await page.screenshot();
// image contains the screenshot bytes
Choose a path with an extension that matches the format you want. Playwright infers the image type from that extension. If no path is supplied, the default image type is PNG.
Choose what to capture
Current viewport
The basic call captures the visible viewport, not the entire scrollable document. This is the right choice for a screenshot intended to show what a visitor sees without scrolling:
await page.screenshot({ path: 'viewport.png' });
fullPage defaults to false, so you do not need to specify it for a viewport-only capture.
Recommended Free Tools
Full scrollable page
Set fullPage: true to capture content beyond the current viewport:
await page.screenshot({ path: 'full-page.png', fullPage: true });
This is useful for a page overview or visual record of long-form content. It does not mean that every hidden or unloaded part of an application becomes visible: the screenshot reflects the page state Playwright has rendered. For example, content that a site loads only after scrolling may need to be brought into view before capture. Avoid assuming a full-page image is equivalent to a visitor scrolling through every interactive state.
Rank #2
- 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
A rectangular region
To capture a fixed rectangle rather than the whole viewport, pass a clip object with its position and dimensions:
await page.screenshot({
path: 'region.png',
clip: { x: 40, y: 80, width: 640, height: 360 }
});
The coordinates and dimensions describe the rectangle to capture. Keep the region within the rendered page area; a clip outside the available content cannot produce the intended crop. Use a locator screenshot instead when the target is a particular element whose position may move as the page changes.
One element
Call screenshot() on a locator to capture a single element. For example:
await page.getByRole('link', { name: 'Learn more' })
.screenshot({ path: 'link.png' });
Locator screenshots wait for actionability checks and scroll the element into view. That makes them more robust than guessing coordinates for a moving page layout. There are two important limits: an overlay covering the target may prevent the element from appearing visibly, and a screenshot of a scrollable container includes only the content currently scrolled into view within that container. Dismiss or hide an overlay deliberately if that matches the desired capture, and scroll a container to the relevant content before taking its screenshot.
Select an image format and pixel scale
Playwright supports PNG, JPEG, and WebP screenshots. The format is inferred from the output filename when one is supplied; for example, use page.jpg or page.webp to request those formats. PNG is lossless and does not use the screenshot quality setting. JPEG’s documented default quality is 80; WebP quality 100 is lossless.
Rank #3
- 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.
await page.screenshot({ path: 'page.jpg', quality: 85 });
await page.screenshot({ path: 'page.webp', quality: 90 });
Use the scale option to decide the pixel density of the output. scale: 'css' produces one image pixel per CSS pixel, often yielding a smaller image. scale: 'device' uses device-pixel resolution and can make the result twice as large or more on high-DPI displays.
await page.screenshot({ path: 'css-scale.png', scale: 'css' });
await page.screenshot({ path: 'device-scale.png', scale: 'device' });
For a stable visual test or a compact preview, CSS scale is often the more convenient comparison target. Choose device scale when the higher pixel resolution is part of what you need to inspect or deliver. Whatever the choice, use the same scale for expected and actual images in visual comparisons.
Make screenshots repeatable
A screenshot is only as consistent as the page state at capture time. Dynamic content, blinking carets, animation, or changing timestamps can produce different images even when the underlying layout is correct. Playwright’s screenshot options let you control several of these sources of variation.
- Hide the caret: avoid a text cursor appearing in one capture but not another.
- Disable animations: finite animations are fast-forwarded to completion; infinite animations are canceled at their initial state and resumed after the screenshot. This is useful for stable test images, but may not represent an in-progress animation a user should see.
- Mask locators: cover selected elements whose content changes between runs, such as a region that displays variable data.
- Apply a stylesheet: override or hide dynamic page elements for the screenshot when that is appropriate to the test.
For example, a screenshot can mask an element that changes on every run:
await page.screenshot({
path: 'stable.png',
animations: 'disabled',
caret: 'hide',
mask: [page.locator('.changing-value')]
});
Use stabilization deliberately. Hiding or masking content can make comparisons repeatable, but it can also conceal a real defect if applied too broadly. If the purpose is to document the live appearance of a page, leave dynamic behavior intact; if the purpose is to compare layout, control only the parts that make the comparison noisy.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #4
- 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 right page state
Do not add arbitrary sleeps just to make a screenshot feel ready. Playwright’s Page API documentation discourages waitForTimeout() in production tests because time-based waits are inherently flaky: a delay may be longer than necessary on one run and too short on another. Prefer a meaningful signal, such as waiting for the target element or asserting that a key piece of content is present.
await page.goto('https://example.com');
await page.getByRole('heading', { name: 'Example Domain' }).waitFor();
await page.screenshot({ path: 'ready.png' });
For interaction-driven pages, wait for the result of the interaction rather than sleeping for a guessed duration. The Playwright Page API notes that waitForLoadState is often unnecessary because Playwright auto-waits before actions. Use a load-state wait only when it addresses a specific navigation or page-state requirement; it is not a general substitute for waiting on the content your screenshot actually depends on.
The screenshot method’s own timeout defaults to 0, meaning no timeout. Do not confuse that with a Playwright Test test timeout or a screenshot assertion timeout: those are separate settings. If you set a screenshot-call timeout, choose it based on the operation and expected page behavior rather than assuming the test runner’s timeout automatically controls it.
Use screenshots in Playwright Test
Compare an expected image
For visual regression testing, use Playwright Test’s toHaveScreenshot() assertion:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallconst { test, expect } = require('@playwright/test');
test('page matches its screenshot', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot();
});
The assertion waits for two consecutive screenshots to match before comparing the result with the expected snapshot. It belongs to the Playwright Test runner; it is not an assertion available in an arbitrary script that merely imports the browser library. On its first use, the test runner establishes the expected image as a snapshot; later runs compare against it.
Best Value
- 【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.
Screenshot assertions disable animations by default. Options such as fullPage, mask, stylePath, and scale let you scope or stabilize the comparison. Make those choices consistent across runs so that changes in capture configuration are not mistaken for changes in the page.
Save screenshots automatically when tests fail
If you want diagnostic images from test runs rather than an expected-image comparison, configure the Playwright Test use.screenshot setting. The documented modes are off, on, only-on-failure, and on-first-failure. Failure-focused modes collect evidence when debugging is most useful without taking a screenshot for every passing test.
// playwright.config.js
module.exports = {
use: {
screenshot: 'only-on-failure'
}
};
Choose on when every test’s image is useful to retain; choose a failure-focused mode when artifacts should concentrate on problems. These configured test artifacts are distinct from calling page.screenshot() yourself and from comparing an image with toHaveScreenshot().
Common screenshot problems and fixes
- The image shows only the visible portion of the page. That is the default viewport capture. Set
fullPage: truefor the scrollable page, or use a locator screenshot for a single element. - The target element is missing or obscured. A locator screenshot scrolls its element into view, but an overlay can still cover it. Handle or hide the overlay if the intended image should show the unobstructed element.
- A screenshot of a scrollable panel omits content. Locator screenshots capture only the content currently scrolled into view in that container. Scroll the container to the content you need before capture.
- The file is not in the requested image format. Check the filename extension; Playwright infers the type from the path. If you omit the path, PNG is the default.
- JPEG or WebP quality changes do not affect a PNG. The quality setting does not apply to PNG. Use a JPEG or WebP path when you intend to use that setting.
- The image differs between otherwise similar test runs. Wait for the relevant page content, then consider hiding the caret, disabling animations, masking only known variable regions, or using a stylesheet to control dynamic elements.
- The capture appears to wait indefinitely. The screenshot API timeout defaults to no timeout. If an operation needs a bound, set its own timeout and distinguish it from the test’s timeout or the screenshot assertion timeout.
- A visual assertion is unavailable in a standalone script.
toHaveScreenshot()is for Playwright Test. Usepage.screenshot()for an image file or buffer outside that test runner.
Or skip the browser setup
If you need a screenshot from a URL without managing Playwright browser setup, ScreenshotNeo provides a one-request API that returns an image or PDF. For a WebP capture, the cURL request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before the capture; each of those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server includes screenshot tools for AI agents, and the free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
How to choose the capture approach
- One-off local image: use
page.screenshot()with a path. - Image data for code: omit the path and process the returned bytes.
- Long page or focused region: choose
fullPage,clip, or a locator according to the content boundary you need. - Visual regression: use
toHaveScreenshot()in Playwright Test and stabilize only the genuinely variable parts. - Failure debugging: configure a screenshot artifact mode in the test runner.
Playwright’s documentation is rolling rather than pinned to a single version. Before relying on a recently added option, check the API reference matching the Playwright version installed in your project.
Frequently Asked Questions
Does Playwright screenshot capture work with browsers other than WebKit?
Yes. The official example uses WebKit, and the documentation also notes that Chromium or Firefox can be used.
Can I pass a Playwright screenshot directly to another function without creating a file?
Yes. Omit the path and use the returned screenshot data in memory.
Quick Recap
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.

