Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

Playwright Screenshot Uses the Wrong Page Size: Set the Viewport and Device Scale Factor

Playwright screenshot dimensions depend on viewport, device scale factor, screenshot scale, and capture extent. Set each intentionally to get the output you expect.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a Playwright screenshot has the wrong dimensions, check three separate settings: the page’s viewport in CSS pixels, the browser context’s deviceScaleFactor, and the screenshot’s scale. Set the viewport before navigation, choose the output scale explicitly, and use fullPage only when you want the whole scrollable document. These settings control layout size, pixel density, and capture area respectively—not the same thing.

Why a Playwright screenshot has the wrong size

A screenshot’s dimensions can differ from what you expect because Playwright separates the page’s layout viewport from its raster density and the region being captured. A viewport of 1280 × 720 means 1280 × 720 CSS pixels; it does not mean the browser window or monitor has those physical-pixel dimensions.

As an Amazon Associate I earn from qualifying purchases.

Setting What it controls Where to set it
Viewport Page layout width and height in CSS pixels Browser context, Playwright Test configuration, or page.setViewportSize()
deviceScaleFactor Device pixel ratio (DPR), which affects device-pixel output Browser context
Screenshot scale Whether output pixels correspond to CSS pixels or device pixels page.screenshot()
fullPage or clip Which part of the page is captured page.screenshot()

For a fixed-size image, make all three decisions intentionally: specify the viewport, set the DPR, and select scale. Playwright documents a default deviceScaleFactor of 1, but relying on defaults for the screenshot scale can make the output ambiguous; set it explicitly. See the Page API and BrowserType API.

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

Set a precise viewport and screenshot size

This JavaScript example requests a 1280 × 720 CSS-pixel viewport, DPR 1, and one output pixel per CSS pixel. It writes a screenshot to page.png:

#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
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    viewport: { width: 1280, height: 720 },
    deviceScaleFactor: 1,
  });
  const page = await context.newPage();

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

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

The intended result is a 1280 × 720 CSS-pixel capture. The code illustrates configuration; actual rendered content and dimensions can also depend on capture options and the page. Playwright’s scale: 'css' makes each CSS pixel correspond to one output pixel. With scale: 'device', each device pixel becomes an output pixel, so a higher DPR produces a larger image. The exact result depends on the DPR. Details are in the screenshot API reference.

Set the viewport before navigation

Prefer setting viewport when creating the browser context, as in the example, so the page loads at its intended layout size. You can also call page.setViewportSize({ width: 1280, height: 720 }), but do so before navigating where possible. Playwright’s API notes that some sites do not expect a phone-sized viewport to change after the page has loaded. See setViewportSize.

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

Use the intended screenshot scale

  • Choose scale: 'css' when you want one output pixel per CSS pixel.
  • Choose scale: 'device' when the image should reflect device-pixel density; output dimensions can be larger than the CSS viewport at DPRs above 1.

Do not change viewport width or height to compensate for an unintended device-pixel scale. That changes page layout, not just raster density.

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

Capture the viewport, the whole page, or a region

Screenshot dimensions also depend on the requested capture area. A normal screenshot captures the visible viewport. Set fullPage: true to capture the full scrollable document; the resulting image can be taller than the viewport. Use clip when you want a specific rectangular region. Neither option changes pixel density: fullPage changes the capture extent, while scale controls CSS-pixel versus device-pixel output. These options are documented in the Page API.

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.
// Full scrollable page
await page.screenshot({ path: 'full-page.png', fullPage: true, scale: 'css' });

// A specific region (coordinates and dimensions are in CSS pixels)
await page.screenshot({
  path: 'region.png',
  clip: { x: 0, y: 0, width: 640, height: 360 },
  scale: 'css',
});

Use one capture-extent choice that matches the desired result: viewport only, full page, or a clipped region.

Set the viewport in Playwright Test

In Playwright Test, set the viewport in the project’s use configuration. If spreading a device preset, put your explicit viewport after the spread so it overrides the preset’s value:

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
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  use: {
    ...devices['Desktop Chrome'],
    viewport: { width: 1280, height: 720 },
  },
});

A device preset supplies settings, including a viewport; the explicit value following the spread takes precedence. Playwright shows this ordering in its emulation guide. If DPR matters to your screenshot, configure it explicitly in the test project’s use options as well, rather than assuming a preset or default matches your target.

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

Debug the dimensions in this order

  1. Check the viewport. Confirm the active context or test project has the intended CSS-pixel width and height. Look for a later configuration or device preset that replaces them.
  2. Check device scale factor. Verify the context’s deviceScaleFactor if you expect device-pixel output. The documented default is 1; set the value explicitly for a predictable setup.
  3. Check screenshot scale. Use 'css' for one output pixel per CSS pixel or 'device' for device-pixel output.
  4. Check capture extent. Confirm whether fullPage or clip is changing the captured area.
  5. Check the rendering environment. For visual comparisons, align browser version and host environment between baseline generation and comparison.

Common causes and fixes

Symptom Likely cause Fix
Image is larger than the viewport dimensions you specified scale: 'device' with a DPR above 1 Use scale: 'css' for CSS-pixel output, or keep device scale and account for the DPR.
Page layout is wider, narrower, or reflowed unexpectedly Wrong viewport, or a device preset overriding the intended viewport Set the explicit viewport on the context or after the preset spread; do so before navigation where possible.
Image is taller than expected fullPage: true captures scrollable content beyond the visible viewport Remove fullPage for a viewport capture or use a suitable clip.
Only part of the expected area appears A clip rectangle constrains the capture Adjust or remove the clip rectangle.
Layout changes after resizing The page was navigated before the viewport was set; some sites do not expect a late size change Set the context viewport before creating or navigating the page.
Visual tests differ between machines despite matching dimensions Rendering can vary with operating system, browser version, settings, hardware, power source, or headless mode Generate and compare baselines in aligned environments and keep browser versions consistent.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make visual screenshot tests more reproducible

Playwright Test’s toHaveScreenshot() waits until two consecutive page screenshots produce the same result before comparing against the expectation. That helps avoid comparing against a transient capture, but it cannot eliminate differences caused by the operating system, browser version, settings, hardware, power conditions, or headless mode. Keep baseline creation and comparison environments aligned where possible. See Visual comparisons and the PageAssertions 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.

Or skip the browser setup

If you need an image or PDF from a URL without managing Playwright contexts, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF. For example, this cURL request saves a WebP screenshot:

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

See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. 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: 1,000 screenshots a month, no card required.

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

Frequently Asked Questions

Does fullPage: true increase screenshot resolution?

No. It expands the captured area to include scrollable page content; the screenshot’s scale determines CSS-pixel or device-pixel output.

Should I use scale: 'css' or scale: 'device'?

Use 'css' when output pixels should match CSS pixels. Use 'device' when you intend device-pixel output and want dimensions to reflect the configured DPR.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.