Set the browser viewport before navigation when you need a predictable visible-page image: await page.setViewportSize({ width: 1280, height: 720 });, then call page.screenshot(). Playwright screenshot size can also mean the full document, a clipped rectangle, an element’s bounds, or output pixel density. Choose the option that matches the result you need.
Set a fixed screenshot size with the viewport
For a screenshot of the currently visible browser page, set the viewport width and height before goto. The values are CSS pixels.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
The resulting image represents a 1280-by-720 CSS-pixel viewport unless another screenshot option changes the output. Set the viewport before navigation whenever possible. Responsive sites select breakpoints and load layout-dependent content during navigation; resizing afterward can produce a different layout or require another reflow.
Set the viewport when creating a context
Use a browser context when several pages should share dimensions:
#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 context = await browser.newContext({
viewport: { width: 1440, height: 900 }
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'desktop.png' });
Context-level settings are convenient for suites and repeated captures. If you need to control the emulated physical screen separately from the viewport, configure the context’s screen and viewport options. Calling page.setViewportSize() resets the screen size, so apply those settings deliberately. See the Playwright Page API for the current behavior.
Four meanings of “screenshot size”
Before changing code, identify which dimension you are trying to control.
| Goal | Playwright setting | What it controls |
|---|---|---|
| Visible browser area | setViewportSize or context viewport |
CSS-pixel width and height used by the page layout |
| Everything in the document | fullPage: true |
Captures the full scrollable page; it does not create a permanently taller viewport |
| A precise rectangle | clip: { x, y, width, height } |
Coordinates and dimensions of the capture region |
| Output pixel density | scale: 'css'` or `scale: 'device'` |
Whether output pixels match CSS pixels or device pixels |
How do I take a full page screenshot in Playwright?
Pass fullPage: true to capture the entire scrollable document:
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('https://example.com');
await page.screenshot({ path: 'full-page.png', fullPage: true });
The viewport width still controls responsive layout. The fullPage option extends the capture through content below the fold; it is not equivalent to setting a very large viewport height. Lazy-loaded content may need to be triggered or waited for before capture. Playwright’s screenshots guide documents full-page behavior and examples.
Recommended Free Tools
How do I screenshot a specific element in Playwright?
Use a locator’s screenshot method when the image should match one element’s rendered bounds:
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
await page.goto('https://example.com');
const card = page.locator('[data-testid="pricing-card"]').first();
await card.waitFor({ state: 'visible' });
await card.screenshot({ path: 'card.png' });
Playwright scrolls the matched element into view and clips the image to its size and position. A scrollable element shows only the content currently inside its scroll position; it does not automatically capture every internal scroll position. Use a page-level clip when you need fixed coordinates instead of a selector.
Capture an exact rectangle with clip
A clip object defines the rectangle in page coordinates:
await page.screenshot({
path: 'header-region.png',
clip: { x: 0, y: 0, width: 1280, height: 180 }
});
x and y identify the top-left corner; width and height define the region. The rectangle must fit within the page’s available screenshot area. For a component that moves with responsive layout, a locator is usually more robust than hard-coded coordinates.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Control CSS pixels versus device pixels with scale
Screenshot output can be scaled independently of the CSS viewport:
await page.screenshot({ path: 'css-pixels.png', scale: 'css' });
await page.screenshot({ path: 'device-pixels.png', scale: 'device' });
scale: 'css': one image pixel per CSS pixel, useful for predictable file dimensions and smaller visual-regression artifacts.scale: 'device': one image pixel per device pixel, the Page API default. On a high-DPI emulation, the file can be larger than the viewport’s CSS dimensions.
Scale changes output density, not the responsive layout width. If a 1280-CSS-pixel viewport produces an unexpectedly wide file, inspect the device scale factor and choose scale: 'css' when CSS-pixel dimensions are required.
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.
How do I change the screenshot size in Playwright?
- Decide whether you need visible viewport, full document, element, crop, or pixel-density control.
- Set
viewporton the context or callpage.setViewportSize({ width, height }). - Do it before
page.goto()for responsive pages. - Wait for the content that determines the final appearance.
- Choose
fullPage,clip, a locator screenshot, and/orscale. - Save the image and verify its actual dimensions with an image tool or your CI artifact viewer.
A reusable capture function
import { chromium } from 'playwright';
export async function capture(url, output, options = {}) {
const browser = await chromium.launch();
const context = await browser.newContext({
viewport: {
width: options.width ?? 1280,
height: options.height ?? 720
}
});
const page = await context.newPage();
await page.goto(url, { waitUntil: options.waitUntil ?? 'networkidle' });
await page.screenshot({
path: output,
fullPage: options.fullPage ?? false,
scale: options.scale ?? 'css',
clip: options.clip
});
await browser.close();
}
await capture('https://example.com', 'example.png', {
width: 1440,
height: 900,
fullPage: true
});
For pages with animations, freeze or wait for the relevant state before capture. For lazy images, scroll or use an application-specific readiness signal; a network-idle event alone does not guarantee that every below-the-fold image has been decoded.
Playwright Test: automatic screenshots are separate
Playwright Test can capture screenshots through its test configuration, but automatic capture is off by default. Configure the Test screenshot option when you want screenshots on test failures or as part of test execution, and set its fullPage property when appropriate. This is separate from calling page.screenshot() yourself. The available settings are listed in the TestOptions API.
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 reinstallCommon size problems and fixes
“Why is my Playwright screenshot twice as large as my viewport?”
The most common cause is device-pixel scaling. The viewport is expressed in CSS pixels, while scale: 'device' writes device pixels. Use scale: 'css' for one output pixel per CSS pixel, or intentionally configure the device scale factor when emulating a device.
The page uses the wrong mobile or desktop layout
Set the viewport before goto, and create a fresh context for each target size. A resize after navigation can trigger a different responsive state than the initial load.
The full-page image is short or missing content
Confirm fullPage: true. Wait for the page’s content, scroll to trigger lazy loading, and wait for images or a page-specific “ready” marker. Full-page capture extends the document; it does not force JavaScript components to render.
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
The element screenshot is the wrong size
Wait for the locator to be visible, select the intended match with .first() or a stricter selector, and check whether the element has internal scrolling. A scrollable element’s screenshot reflects its current scroll position.
The clip option throws an error or cuts off content
Ensure the rectangle uses non-negative coordinates and fits within the page. Prefer a locator for responsive components whose position changes between viewport sizes.
Fonts, animations, or late resources make captures inconsistent
Wait for fonts and application data, disable or pause animations in a test stylesheet, and capture after a deterministic readiness condition rather than relying only on a timeout. Keep the browser, viewport, scale, and color scheme consistent in visual tests.
Performance, reliability, and file-size trade-offs
- Smaller viewports and CSS scaling generally produce smaller files and faster artifact handling.
- Full-page captures require more memory for long documents; split very long reports into sections when a single giant image is not required.
- Device-pixel output preserves high-DPI detail but increases image dimensions and storage.
- Fresh contexts per viewport reduce state leakage between responsive cases, at the cost of browser setup time.
- Deterministic waits improve visual consistency; arbitrary long delays slow the suite without proving that the page is ready.
Or skip the browser setup
ScreenshotNeo provides a website screenshot API when you want a URL-to-image request instead of managing Playwright browsers. Its clean-shot pipeline accepts cookie and consent banners, removes more than 60 known consent platforms plus newsletter popups and chat widgets, and lets you turn each cleanup step off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and whether the request was billed. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
The API supports viewport and device presets, full-page capture, CSS-selector element capture, dark mode, retina scale, PDF settings, custom CSS and JavaScript, click and wait actions, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use the ScreenshotNeo documentation for authentication and all options. A minimal request is:
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
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account.
FAQ
Frequently Asked Questions
Does changing the viewport change the website’s CSS breakpoints?
Yes. Responsive CSS and JavaScript observe the viewport dimensions, so a new width can select a different layout. Apply the target viewport before navigation for the most representative initial render.
Can I combine fullPage and clip?
Use the combination only when the resulting region is valid for your Playwright version and page geometry. In most workflows, choose either a full document capture or a deliberate rectangle; use a locator for component-level images.
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 problemsWhich image format should I use?
PNG is lossless and useful for text or visual tests. JPEG or WebP can reduce storage when some compression is acceptable; the format does not change viewport dimensions.
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.

