Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesUse Playwright’s page.screenshot() to capture a browser page. By default it saves the visible viewport; set fullPage: true for the full scrollable document, or use a locator’s screenshot() method to capture one element. You can save the image to a file or use the returned buffer in your code.
Set up a Playwright screenshot
The examples below use Playwright’s JavaScript API. They assume Node.js and Playwright are installed in the project. If you have not set up a project yet, run:
npm init -y
npm install playwright
npx playwright install chromium
Save this as screenshot.js and run it with node screenshot.js:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
try {
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({ path: 'screenshot.png' });
} finally {
await browser.close();
}
})();
Replace https://example.com with the page you need. The screenshot call writes screenshot.png in the process’s current working directory. The browser is closed in a finally block so it is also cleaned up if navigation or capture fails.
#1 Best Overall
For an existing Playwright test or script that already has a page object, the essential call is simply await page.screenshot({ path: 'screenshot.png' });. A page screenshot captures the current viewport unless you request a different capture area.
Choose what to capture
Visible viewport
The default screenshot is the currently visible browser viewport. Set its dimensions when creating the page or browser context if the output needs a predictable layout:
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto('https://example.com');
await page.screenshot({ path: 'viewport.png' });
The viewport is measured in CSS pixels. A page designed responsively may render different content at a different width, so choose dimensions that match the layout you intend to inspect.
Full scrollable page
Set fullPage: true to capture the full scrollable page as though it fit on a very tall screen:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →await page.screenshot({ path: 'full-page.png', fullPage: true });
This captures the document beyond the visible viewport; it does not mean that an individual scrollable panel will automatically be expanded to show all its contents. Long pages can produce large image files, and page content that loads only after scrolling may need separate handling before capture.
One element
Use a locator’s screenshot method to capture the element matched by a CSS selector:
await page.locator('.header').screenshot({ path: 'header.png' });
Playwright waits for the locator to become actionable and scrolls the element into view. If another element covers part of it, the screenshot does not reveal the covered area. A scrollable element shows only the content currently scrolled into view, not necessarily its entire internal contents.
Rank #2
A rectangular region
Use clip to capture a rectangle within the page viewport. Its coordinates and dimensions are CSS pixels:
await page.screenshot({
path: 'region.png',
clip: { x: 100, y: 120, width: 600, height: 350 }
});
Choose coordinates that fit the page’s rendered viewport. A clipped screenshot is useful when you need a specific region but do not have a convenient element locator.
Pick an output format and pixel scale
PNG, JPEG, and WebP
Playwright can produce PNG, JPEG, or WebP images. Set type explicitly when you want a format that does not follow the file path’s extension:
await page.screenshot({ path: 'page.webp', type: 'webp', quality: 85 });
The quality option applies to lossy-capable JPEG and WebP output, not PNG. The Page screenshot API documents a default JPEG quality of 80 and WebP quality of 100, which is lossless. Consider the trade-off: lossy quality settings can reduce file size, while PNG is appropriate when you want lossless output and do not need a quality setting. Check the API reference for the Playwright version installed in your project if you depend on a particular default.
CSS pixels or device pixels
The Page screenshot API’s scale option controls the output pixel scale:
Free tools Windows power users keep installed
One-click scans. No signup required.
scale: 'css'produces one image pixel per CSS pixel.scale: 'device'uses device pixels and can produce a larger, high-DPI image.
The Page screenshot API documents device as its default. That default should not be assumed for other screenshot-related APIs, including Playwright Test screenshot assertions, which can have different defaults. Specify the scale when output dimensions matter:
await page.screenshot({ path: 'page.png', scale: 'css' });
For consistent artifacts, keep the browser engine, viewport, device scale factor, and screenshot options consistent between runs. A browser context’s device scale factor affects the environment in which the page renders.
Return an image buffer instead of writing a file
When the next step is image processing, uploading, or passing the capture to another function, omit path. The call returns image data as a buffer:
const imageBuffer = await page.screenshot({ type: 'png' });
// Pass imageBuffer to an image-processing or upload function.
Choose the output type explicitly if downstream code expects a particular format. If you do provide path, Playwright saves the screenshot there; without it, your program is responsible for storing or using the returned buffer.
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 →Reduce visual variation in captures
Animations, a blinking text caret, and changing page content can make screenshots differ even when the layout has not meaningfully changed. Playwright provides options that can make selected captures more stable, but they should be used with care:
animations: 'disabled'fast-forwards finite animations and cancels infinite animations to their initial state for the screenshot.caret: 'hide'hides the text caret during capture.maskcan cover selected locators, andstylecan inject CSS for the capture.
await page.screenshot({
path: 'stable.png',
animations: 'disabled',
caret: 'hide',
mask: [page.locator('.timestamp')],
style: '.dynamic-banner { visibility: hidden !important; }'
});
Mask or hide only content that is intentionally variable. A broad mask or injected style can conceal an actual rendering or layout regression rather than making the comparison more useful. The injected style screenshot option was added in Playwright v1.41; maskColor was added in v1.35. Verify that the installed version supports any version-specific option you use.
Use screenshots in visual tests
A one-off call to page.screenshot() creates an image; it does not itself compare that image with a baseline. Playwright Test provides screenshot assertions for visual comparisons. Those assertions support configured differences, including a pixel threshold and a maximum number or ratio of differing pixels.
Keep the distinction clear in a test suite: use page.screenshot() when you need an artifact or buffer, and a Playwright Test screenshot assertion when you want the test runner to compare the current rendering with a stored baseline. A stable comparison also depends on controlling viewport, browser engine, device scale factor, and dynamic content. Do not assume byte-identical images across different engines or environments without verifying that for your own setup.
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 matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Capture across browser engines
Playwright supports screenshot workflows with Chromium, Firefox, and WebKit. If you need cross-browser coverage, run the same capture against the engines your users or test plan require, and keep context settings consistent where possible. The browser engine and context configuration are part of the conditions that produced an image; changing either can change the rendered result.
Rank #4
Device scale factor is configured on the browser context. For example, create a context with a chosen scale factor, then open a page in that context:
const context = await browser.newContext({
viewport: { width: 1280, height: 800 },
deviceScaleFactor: 1
});
const page = await context.newPage();
For a repeatable set of artifacts, record the engine and context settings alongside the images. Avoid treating screenshots from different browser engines or scale factors as directly interchangeable baselines.
Or skip the browser setup
If you need a screenshot from a URL without launching and managing a local browser, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers.
For example, this cURL command saves a WebP screenshot of the target URL. See the ScreenshotNeo documentation for API details:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo also provides an MCP server for AI agents, with tools named take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and no card.
Troubleshoot common screenshot problems
The output file is missing
Check the working directory from which the Node process ran and confirm the value of path. A relative path is resolved from the process’s current working directory, not necessarily the folder containing the JavaScript file. Use an absolute path if the script is launched from different directories.
The capture is blank or incomplete
Make sure navigation has completed before calling screenshot(). For pages that load content asynchronously, wait for a meaningful selector or other application-specific readiness condition rather than assuming the first document response means all content is rendered. A full-page screenshot captures the document’s scrollable page, but content that has not yet loaded cannot appear in the image.
Recommended Free Tools
An element is missing or partly covered
Confirm that the locator matches the intended element and that it is visible. Locator screenshots scroll the matched element into view, but an overlay can still cover it. Dismiss or wait for the overlay if that is appropriate for the capture; do not expect the screenshot operation to reveal pixels obscured by another element.
The screenshot differs between runs
Compare the viewport, device scale factor, browser engine, and timing conditions. Disable animations or hide a specific unstable element only when that variability is irrelevant to the test. If the content itself changes, wait for a stable application state or use a carefully scoped mask rather than masking broad areas.
The image is too large or the wrong dimensions
Check whether you used fullPage: true, a device-pixel scale, or a high device scale factor. For a viewport-sized artifact, omit fullPage and use scale: 'css' when one output pixel per CSS pixel is the desired result. Choose JPEG or WebP quality settings when lossy output is acceptable.
An option is rejected or unavailable
Check the installed Playwright version and the API used. The Page API documents page.screenshot() as available since v1.9, and the Locator API documents locator.screenshot() since v1.14. Later options have their own minimum versions—for example, maskColor in v1.35, injected style in v1.41, and screenshot signal in v1.62. The screenshots guide may reflect upcoming documentation, so verify version-specific behavior against the API reference and the package actually installed in your project.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Plan capture speed, reliability, and storage
Screenshot cost in a Playwright script is chiefly operational: browser startup, navigation, page readiness, capture size, and whatever processing or storage your application performs. Reusing a browser for multiple pages can avoid repeatedly launching it, while separate contexts can isolate settings and state. Keep browser and context cleanup reliable, especially in long-running jobs, and handle navigation and capture errors so one failing URL does not silently produce a misleading artifact.
Full-page captures and device-pixel images can contain many more pixels than a viewport capture at CSS scale. If storage or transfer size matters, choose a suitable image format and capture scope, and process the returned buffer or saved file as needed. For visual tests, prioritize comparable capture conditions over trying to make files smaller: changes to format, scale, or browser context can affect the artifact being compared.
Frequently Asked Questions
Can Playwright take a screenshot without saving it to disk?
Yes. Call page.screenshot() without a path; the result is an image buffer your code can pass to another operation.
Does a full-page screenshot include everything inside a scrollable panel?
Not necessarily. fullPage: true captures the scrollable document; an element screenshot of a scrollable panel shows its currently scrolled content.
Are Playwright screenshots guaranteed to match pixel-for-pixel across browsers?
No such guarantee is established here. Browser engine and context settings affect the capture environment, so compare artifacts under controlled conditions.
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.

