Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Playwright’s page.screenshot() method for a browser viewport, add fullPage: true for the complete scrollable document, or call locator.screenshot() for one element. The methods can write PNG, JPEG, or WebP files, or return image bytes for processing.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
This guide shows how to control capture scope, output format, resolution, masking, animation, and timing; how to make screenshots reliable in tests; and how to diagnose common failures.
Set up a page and capture the current viewport
A Playwright screenshot starts with a browser, a page, navigation to the target URL, and a call to page.screenshot(). With only a path, Playwright captures what is currently visible in the viewport and saves a PNG.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com', { waitUntil: 'load' });
await page.screenshot({ path: 'viewport.png' });
await context.close();
await browser.close();
})();
Keep the browser open until the screenshot promise resolves. Closing the context first can leave you with an incomplete file or an exception. A context is useful when you need a particular viewport, locale, cookies, or other isolated settings; browser.newPage() is a shorter option for simple scripts.
#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
Wait for the state you actually want to capture
page.goto() completing does not guarantee that every image, font, or client-rendered component is ready. Wait for a specific selector when that is the meaningful condition:
await page.goto('https://example.com/dashboard');
await page.locator('[data-testid="dashboard"]')
.waitFor({ state: 'visible' });
await page.screenshot({ path: 'dashboard.png' });
For a fixed animation or delayed widget, use an explicit delay only when a deterministic selector or application event is not available. Waiting for a real UI condition is usually less brittle than guessing a number of milliseconds.
Choose the capture scope
| Need | Playwright call | Result |
|---|---|---|
| Visible browser view | page.screenshot({ path: 'view.png' }) |
Current viewport |
| Entire document | page.screenshot({ path: 'page.png', fullPage: true }) |
Full scrollable page |
| One component | page.locator('.header').screenshot({ path: 'header.png' }) |
Matched element’s bounding box |
| Specific rectangle | page.screenshot({ clip: { x, y, width, height } }) |
Clipped area in page coordinates |
Full-page screenshots
Set fullPage: true to capture the full scrollable page instead of only the visible viewport:
Windows 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 reinstallOutdated 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 matchawait page.screenshot({
path: 'full-page.png',
fullPage: true
});
Full-page capture may expose content that is loaded only after scrolling. If the site uses lazy loading, scroll through the page first so those resources have a chance to load:
await page.goto('https://example.com/catalog');
await page.evaluate(async () => {
await new Promise(resolve => {
let last = 0;
const timer = setInterval(() => {
window.scrollBy(0, window.innerHeight);
const now = document.documentElement.scrollTop;
if (now === last) {
clearInterval(timer);
resolve();
}
last = now;
}, 100);
});
});
await page.screenshot({ path: 'catalog.png', fullPage: true });
Use this only when scrolling itself does not trigger unwanted state changes. For a stable test, prefer an application signal that all content is ready.
Element screenshots
Use a locator when you want one component. Playwright waits for the locator to be actionable and scrolls the element into view before capturing it:
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
const card = page.locator('.product-card').first();
await card.screenshot({ path: 'product-card.png' });
If the locator matches multiple elements, narrow it with .first(), .nth(), or a more specific selector. An overlay can still cover the element at capture time. A scrollable element is captured with the contents currently visible inside that element, not an automatic image of its entire internal scroll area.
The older ElementHandle.screenshot() method is discouraged in favor of locator-based screenshots, which preserve Playwright’s waiting and retry behavior.
Save a file or process the returned bytes
Passing path writes the image to disk. Omitting it returns a Buffer, which you can upload, hash, transform, or attach to a test report without creating an intermediate file.
const imageBuffer = await page.screenshot({ type: 'png' });
console.log(`Captured ${imageBuffer.length} bytes`);
// send imageBuffer to storage or an HTTP client
The supported image types are PNG, JPEG, and WebP. PNG is the default. JPEG and WebP are useful when file size matters, but lossy quality settings can change pixels and therefore affect visual comparisons.
Format and quality
await page.screenshot({
path: 'compressed.webp',
type: 'webp',
quality: 85
});
await page.screenshot({
path: 'photo.jpg',
type: 'jpeg',
quality: 80
});
JPEG quality defaults to 80. WebP quality defaults to 100, which is lossless; lower WebP values are lossy. omitBackground can produce transparency for formats that support it, but it does not apply to JPEG.
Control dimensions and high-DPI output
Playwright can render at CSS-pixel scale or device-pixel scale. scale: 'css' produces one output pixel per CSS pixel and usually keeps files smaller. scale: 'device' represents device pixels and can produce images twice as large, or larger, on high-DPI displays.
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.
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 1
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'css-scale.png', scale: 'css' });
await page.screenshot({ path: 'device-scale.png', scale: 'device' });
Choose CSS scale when snapshots must be easy to review and storage size is important. Choose device scale when you are validating high-density output or matching a device-pixel artifact.
Make screenshots deterministic
Freeze animation and the caret
Moving animations, blinking carets, and transitions can change pixels between otherwise identical captures. Screenshot options can disable animations and control caret rendering:
await page.screenshot({
path: 'stable.png',
animations: 'disabled',
caret: 'hide'
});
Disabling animation is especially useful for visual regression tests. If the animation itself is what you are testing, leave it enabled and control the exact time at which you capture.
Free tools Windows power users keep installed
One-click scans. No signup required.
Mask dynamic or private regions
Use mask with locators to cover changing values such as timestamps, avatars, ads, or personal data. The covered areas use maskColor:
await page.screenshot({
path: 'account.png',
mask: [
page.locator('[data-testid="last-login"]'),
page.locator('.user-email')
],
maskColor: '#777777'
});
Masking keeps a screenshot’s layout useful while preventing unstable or sensitive text from entering an artifact.
Inject styles or remove the background
The style option lets you inject CSS for the capture, which is convenient for hiding a test-only banner or forcing a visual state. omitBackground: true removes the default page background when the selected output format supports transparency.
await page.screenshot({
path: 'component-transparent.png',
omitBackground: true,
style: '.debug-toolbar, .cookie-banner { display: none !important; }'
});
Use screenshots in Playwright Test
Playwright Test provides toHaveScreenshot() for visual assertions:
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
import { test, expect } from '@playwright/test';
test('home page remains stable', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot('home.png');
});
The assertion takes screenshots until two consecutive captures match, then compares the result with the stored expectation. A first run creates a baseline; later runs report pixel differences.
Keep the comparison environment consistent
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 pixel consistency matters. Pin the browser version used by your project, use a fixed viewport, and avoid capturing live clocks, randomized content, rotating ads, or data that changes between runs.
Useful options at a glance
| Option | What it controls | Typical use |
|---|---|---|
path |
Output filename | Save an artifact to disk |
type |
png, jpeg, or webp |
Choose compatibility or compression |
quality |
JPEG/WebP quality | Trade file size against fidelity |
fullPage |
Whole scrollable document | Long-page documentation or reports |
clip |
Rectangle to capture | Fixed-region screenshots |
scale |
CSS or device pixels | Control dimensions and density |
mask, maskColor |
Cover locator bounding boxes | Hide dynamic or sensitive areas |
animations |
Animation handling | Stabilize visual tests |
caret |
Caret visibility | Prevent blinking-caret differences |
omitBackground |
Transparent background where supported | Component assets and compositing |
style |
Injected capture-only CSS | Hide or restyle capture-time elements |
Troubleshoot failed or incorrect captures
The screenshot is blank or the page is not ready
- Cause: Navigation finished before client-side content rendered, or the page failed to load.
- Fix: Check the URL response and console errors, then wait for a meaningful visible locator before calling
screenshot().
A full-page image misses lazy-loaded content
- Cause: Images or sections load only after they approach the viewport.
- Fix: Scroll to trigger lazy loading, wait for the image selectors, and then capture with
fullPage: true.
An element screenshot times out
- Cause: The locator matches nothing, remains hidden, or is covered by another element.
- Fix: Verify the selector in the rendered DOM, wait for
state: 'visible', and remove or hide blocking overlays for the capture.
Visual tests fail even though the UI looks unchanged
- Cause: Different OS, browser build, headless mode, hardware, animation state, fonts, or dynamic data.
- Fix: Run baseline and comparison in the same controlled environment; disable animations, hide the caret, and mask changing regions.
The output file is unexpectedly large
- Cause: Device-pixel scale, a very large full-page image, or lossless compression.
- Fix: Use
scale: 'css', capture only the needed scope, or select JPEG/WebP with an appropriate quality value.
A transparent screenshot is opaque
- Cause: JPEG cannot represent transparency, or the page itself paints a background.
- Fix: Use PNG or WebP, set
omitBackground: true, and remove background styles with thestyleoption.
Performance, reliability, and cost considerations
Viewport captures are generally smaller and faster than full-page images. Element and clipped screenshots reduce both rendering work and artifact size when a whole page is unnecessary. Reusing a browser process for multiple pages avoids repeated startup overhead, while separate contexts keep cookies and settings isolated.
For repeatable automation, treat screenshots as an output of a controlled rendering pipeline: pin browser dependencies, set a known viewport and device scale, wait on application state, freeze animations, and keep test data stable. Store the returned buffer directly when a file is not needed; this avoids disk I/O in upload or comparison workflows.
Recommended Free Tools
Or skip the browser setup
If you need a clean image from a URL rather than browser automation code, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled.
Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation for parameters. This example captures Stripe as WebP:
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.
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 from 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)
Or from 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 also supports full-page and CSS-selector captures, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, pre-capture clicks, waits for selectors, delays or network idle, ad/tracker/request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.
Every feature is available on every plan: 1,000 screenshots per month free with no card, Starter at $5 for 3,000, Growth at $15 for 15,000, Pro at $39 for 60,000, Scale at $99 for 250,000, and Business at $249 for 1,000,000. Yearly billing gives two months free. Start with the free ScreenshotNeo account and get 1,000 screenshots a month without a card.
Frequently Asked Questions
Can Playwright capture a screenshot without saving a file?
Yes. Omit the path option and page.screenshot() returns a Buffer that your code can process or upload.
Which method should replace ElementHandle screenshots?
Use locator.screenshot(). The locator API is the recommended approach and includes actionability waiting and scrolling behavior.
Why does a scrollable element screenshot show only part of its content?
An element screenshot captures the content currently visible inside that scrollable element; it does not automatically stitch the element’s internal scroll area.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →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.

