DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 a Fixed Viewport and Device Scale Factor for Playwright Screenshot Tests

Set a fixed Playwright viewport and device scale factor in test configuration or at context creation, then keep screenshot scale and browser settings consistent across baselines.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set viewport and deviceScaleFactor explicitly in your Playwright Test configuration or browser context. For example, a 1280 × 720 CSS-pixel viewport at device scale factor 1 gives screenshot tests a defined starting environment instead of relying on browser or host-window sizing.

Set both values in Playwright Test configuration

For tests using Playwright Test, define the settings under use in playwright.config.ts:

As an Amazon Associate I earn from qualifying purchases.

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    viewport: { width: 1280, height: 720 },
    deviceScaleFactor: 1,
  },
});

This applies the same viewport and emulated device pixel ratio to pages created by the test runner. The values are explicit even though Playwright documents defaults of 1280 × 720 and a device scale factor of 1; explicit configuration makes the intended baseline clear. See the Playwright TestOptions reference.

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

Set the values on a browser context

If you create contexts directly rather than using Playwright Test’s configuration, pass both options to browser.newContext() before creating pages or navigating:

#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
import { chromium } from 'playwright';

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: 'baseline.png' });
await browser.close();

Context-level settings are useful when every page in that context should share one environment. The BrowserType API reference documents context options.

Understand viewport, device scale factor, and screenshot scale

  • viewport is the page’s width and height in CSS pixels. It affects responsive layout, such as whether a site uses its desktop or mobile breakpoints.
  • deviceScaleFactor emulates the device pixel ratio. Set it explicitly so a baseline is not compared with a run configured at a different ratio.
  • The screenshot option scale controls output dimensions: 'css' produces one image pixel per CSS pixel, while 'device' produces one image pixel per device pixel. A device-scale capture can therefore have more pixels than a CSS-scale capture.

Keep these settings distinct when diagnosing image-size changes: the CSS viewport determines layout dimensions, the device scale factor emulates pixel density, and screenshot scale determines how those dimensions map to the output image. Playwright documents screenshot behavior in its Page API reference.

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

Choose the right place to configure the viewport

Use context options for a stable test environment

Set viewport and deviceScaleFactor at context creation when all pages in that context should use the same dimensions and pixel ratio. This also lets you configure screen alongside the viewport if your test needs a specific emulated screen size.

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

Use page.setViewportSize() for an intentional per-page change

page.setViewportSize({ width, height }) changes an existing page’s viewport. For responsive sites, apply it before navigation when possible: many sites are not designed to have their size changed after loading. This method also resets the page’s screen dimensions, so use context-level screen and viewport options if both need precise control. See the Page API reference.

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.

Keep screenshot baselines deterministic

  • Avoid viewport: null when you need repeatable screenshot dimensions. Playwright describes null viewport sizing as dependent on the operating-system window, making it nondeterministic.
  • Set the device scale factor explicitly, even when using the documented default of 1.
  • Choose screenshot output scale deliberately and keep it consistent between baseline creation and later comparisons.
  • For dynamic content, Playwright screenshots can apply a stylesheet or mask selected locators. Use these controls to hide or cover regions that should not determine the visual comparison.
  • Record the browser engine, viewport, device scale factor, and screenshot output scale alongside each baseline. These are separate configuration axes.

Run separate browser or device configurations with projects

When a test must cover multiple engines or emulated devices, use Playwright Test projects to run configurations such as Chromium, Firefox, WebKit, or device presets. Keep each screenshot baseline associated with its intended project and settings rather than comparing images captured under different engines, viewport dimensions, or pixel ratios. See Playwright Projects and Playwright’s device emulation guidance.

Troubleshoot mismatched screenshots

The page has a different layout than the baseline

Check the configured viewport width and height first. Confirm that the context or test configuration is being used for the page, and avoid changing the viewport after navigation unless that is the behavior you are testing.

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

The screenshot image dimensions differ

Check both deviceScaleFactor and the screenshot scale option. A device-scale image can be larger than a CSS-scale image even when the CSS viewport is unchanged.

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

The reported screen dimensions do not match expectations

If you called page.setViewportSize(), remember it resets screen. Configure both screen and viewport when creating the context if the emulated screen size matters.

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.

Runs vary by machine or window

Look for viewport: null or other configuration that makes the capture depend on the operating-system window. Set fixed context or test options instead.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a one-request screenshot of a public page, ScreenshotNeo returns an image or PDF from a URL. See the ScreenshotNeo API documentation for its parameters and output options.

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

ScreenshotNeo accepts cookie banners before capture and removes supported consent banners, newsletter popups, and chat widgets. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides screenshot tools for AI agents, and the free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. It is an API alternative, not a replacement for configuring local Playwright screenshot tests or their browser-specific baselines.

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

Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

What viewport and device scale factor does Playwright use by default?

Playwright’s current BrowserType and TestOptions documentation lists a 1280 × 720 viewport and a device scale factor of 1. Set them explicitly when those values define your intended screenshot baseline.

Does deviceScaleFactor change the CSS viewport?

No. The viewport sets page dimensions in CSS pixels; deviceScaleFactor emulates device pixel ratio. Screenshot output scale separately determines whether output pixels correspond to CSS or device pixels.

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.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan

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.