Set the viewport’s pixel width and height before navigating, then call page.screenshot(). For a one-off page, use page.setViewportSize(); configure the browser context or Playwright Test project when the same size should apply more broadly.
Set a custom viewport for one page
In Playwright Library, call page.setViewportSize() with an object containing width and height, both in pixels. Set it before page.goto() so the site loads with the intended responsive viewport.
As an Amazon Associate I earn from qualifying purchases.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
} finally {
await browser.close();
}
})();
Save this as a JavaScript file in a project with Playwright installed, then run it with Node.js. It writes screenshot.png in the current directory. The API method is setViewportSize, not Puppeteer’s setViewport. Playwright’s Page API notes that changing viewport can reset the page’s screen size and that some websites do not expect a phone-sized viewport to change after loading. See the Page API reference.
Recommended Free Tools
Choose where to configure the viewport
Use page-level configuration for a single page, a browser context for pages sharing the same environment, or Playwright Test configuration for a test or project. Context configuration is also the right place to set viewport alongside screen and device-emulation options.
#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
For every page in a browser context
const context = await browser.newContext({
viewport: { width: 1280, height: 720 },
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'context-shot.png' });
For Playwright Test
import { test } from '@playwright/test';
test.use({ viewport: { width: 1280, height: 720 } });
test('capture at a custom viewport', async ({ page }) => {
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
});
To set a default for a test project rather than an individual test, place viewport in that project’s use configuration in the Playwright configuration file. The emulation guide documents viewport and device settings.
For a device preset with a custom viewport
Spread the device descriptor first and then specify your viewport so your explicit dimensions override the descriptor’s viewport. Include deviceScaleFactor if the intended device pixel ratio matters as well.
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 { chromium, devices } = require('playwright');
const browser = await chromium.launch();
const context = await browser.newContext({
...devices['iPhone 13'],
viewport: { width: 390, height: 844 },
deviceScaleFactor: 2,
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'mobile.png' });
await browser.close();
Use a device preset when you need its emulation settings, not just a convenient viewport size. A viewport and device pixel ratio are separate choices; consult the emulation guide for the configuration supported by your installed Playwright version.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC 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 & 11Choose what the screenshot includes
By default, page.screenshot() captures the visible viewport. Choose the capture extent and output scale deliberately:
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.
- Viewport: omit extent options to capture what is currently visible.
- Full page: use
fullPage: trueto capture the scrollable document. - Rectangle: use
clipwith pixel coordinates and dimensions to capture a specific region. - CSS-pixel output:
scale: 'css'produces one output pixel per CSS pixel. - Device-pixel output:
scale: 'device'uses device pixels and can produce substantially larger high-DPI images.
await page.screenshot({ path: 'full-page.png', fullPage: true });
await page.screenshot({ path: 'css-pixels.png', scale: 'css' });
await page.screenshot({ path: 'device-pixels.png', scale: 'device' });
await page.screenshot({
path: 'region.png',
clip: { x: 0, y: 0, width: 640, height: 360 },
});
The screenshot API also supports file paths, PNG/JPEG/WebP output, JPEG or WebP quality options, and transparent backgrounds for supported formats. It can capture an element, too. For exact option behavior, check the Page API reference for your installed release. If you omit path, page.screenshot() returns an image buffer you can process in memory. The screenshot guide covers the basic capture workflow.
Make visual comparisons reproducible
A fixed viewport controls the page’s CSS layout width and height, but it does not guarantee identical pixels across machines. For useful visual comparisons, keep the operating system, browser version, browser settings, hardware conditions, and headless mode consistent. Playwright’s visual comparisons guidance explains why environment consistency matters.
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
- Use the same viewport dimensions and device scale factor in each run.
- Use the same browser and installed Playwright version.
- Keep operating system, browser settings, and headless mode consistent.
- Wait for the page content you care about before capturing; otherwise timing or incomplete rendering can change the image.
Troubleshoot viewport and screenshot problems
The page still looks like the old viewport
Set the viewport before navigation, rather than changing it after the page loads. If you need a shared size, create the context with viewport before making its pages.
The screenshot is smaller or larger than expected
Check whether you requested CSS pixels or device pixels. scale: 'device' can increase output dimensions on a high-DPI emulated device. Also distinguish the viewport-sized default from fullPage: true, which captures the full scrollable document.
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.
The image differs across machines
Matching viewport dimensions alone is not enough for pixel-for-pixel comparisons. Align browser version, operating system, settings, hardware conditions, and headless mode before treating differences as page changes.
The API method name does not work
For Playwright pages, use page.setViewportSize({ width, height }). The similarly named Puppeteer method is not the Playwright Page API method.
Or skip the browser setup
If you need a screenshot endpoint instead of managing a local Playwright browser, ScreenshotNeo returns an image or PDF from one GET request. Its compatible parameter names also make switching from other screenshot APIs easier. See the ScreenshotNeo API documentation.
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan.
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.




