Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How to Set the Viewport Size for Playwright Screenshots

Set the Playwright viewport in pixels at page, context or test scope—and distinguish viewport size from full-page capture and screenshot pixel scale.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a Playwright page’s viewport with page.setViewportSize({ width, height }), using pixel dimensions. For responsive pages, do it before navigation so the site loads at the intended size. A normal screenshot then captures the visible viewport; use fullPage: true to capture the full scrollable page.

Set the viewport on a page

For a single page, set its viewport before calling page.goto():

As an Amazon Associate I earn from qualifying purchases.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  await page.setViewportSize({ width: 640, height: 480 });
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });

  await browser.close();
})();

width and height are pixels. Choose dimensions that match the layout or device behavior you want to capture; 640 × 480 is only an example. Playwright recommends setting the size before navigation because some sites do not expect a phone-sized page to be resized after loading. The page API also notes that changing the viewport resets the page’s screen size. See the Playwright Page API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Resize an existing page

If you need to resize after creating or navigating to a page, call await page.setViewportSize({ width, height }) before taking the screenshot. The page API documents that pages in the same browser can have different viewport sizes. Resizing after navigation may trigger different responsive behavior than loading the site at that size, so set it early when the initial layout matters.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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

Choose the right configuration scope

Where to set it Use it for Example
Page One page or a late resize await page.setViewportSize({ width: 640, height: 480 });
Browser context A shared default for pages created in that context const context = await browser.newContext({ viewport: { width: 640, height: 480 } });
Playwright Test project All tests in a configured project use: { viewport: { width: 1600, height: 1200 } }
Playwright Test test or describe block A targeted test or group of tests test.use({ viewport: { width: 1600, height: 1200 } });

Context and test configuration are documented in Playwright Emulation. Use a context viewport when several pages should share the same dimensions. Use Playwright Test’s project use settings for a project-wide default, or test.use() for a particular test scope.

Override a device preset’s viewport

Device descriptors include viewport and other emulation settings. If a preset is useful but its dimensions do not fit your test, provide an explicit viewport after spreading the descriptor:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    ...devices['iPhone 13'],
    viewport: { width: 390, height: 844 },
  });
  const page = await context.newPage();

  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });

  await browser.close();
})();

The explicit viewport after the spread overrides the dimensions from the descriptor. Device emulation can also set a device scale factor; that setting is separate from viewport width and height.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure a viewport in Playwright Test

To use the same viewport throughout a project, set it in the project’s use options in playwright.config.ts. For a test-specific setting, use test.use():

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • 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.
import { test } from '@playwright/test';

test.use({
  viewport: { width: 1600, height: 1200 },
});

test('captures at the configured viewport', async ({ page }) => {
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });
});

The dimensions here are an example, not a universal recommendation. Set the viewport to the target layout you need to test or document.

Understand viewport size versus screenshot dimensions

Three separate controls affect what a screenshot represents:

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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
  • Viewport: the page’s visible browser area, set by width and height.
  • Capture extent: the visible viewport by default, or the full scrollable page with fullPage: true.
  • Pixel scale: the mapping from CSS pixels to image pixels, set with the screenshot scale option.

For a full-page capture, keep the viewport configuration and add fullPage:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({ path: 'full-page.png', fullPage: true });

fullPage: true changes how much of the page is captured; it does not set or enlarge the configured viewport. For image pixel dimensions, consider the screenshot scale separately. With scale: 'css', output uses one image pixel per CSS pixel. With scale: 'device', output uses device pixels, so a high-DPI page can produce an image two times as large or more. These options are described in the Page API.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot unexpected screenshot sizes

  • The page uses the wrong responsive layout: Set the viewport before page.goto(). A site may render differently when resized only after it loads.
  • The PNG dimensions are larger than expected: Check the screenshot scale. 'device' uses device pixels; use 'css' for one output pixel per CSS pixel.
  • The screenshot is only the visible portion: Add fullPage: true. This changes capture extent, not viewport dimensions.
  • The page’s screen dimensions do not match the viewport: page.setViewportSize() resets screen size. Set both screen and viewport through browser.newContext() options when both need explicit control.
  • A device preset uses unexpected dimensions: Override its viewport in context options after spreading the device descriptor.

Or skip the browser setup

ScreenshotNeo can return a screenshot or PDF with one GET request, without setting up a Playwright browser locally. The API accepts a URL and supports viewport options; the examples below use the documented API. See the ScreenshotNeo documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Cookie banners, newsletter popups and chat widgets are removed before capture by default; those cleanup steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server offers take_screenshot, get_page_info and capture_pdf for AI agents using Claude, Cursor or another MCP client. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.