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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Redmond desk3 min

Playwright Screenshots on Windows: Set Viewport and Device Scale Factor

Configure Playwright’s viewport and device scale factor before navigation, then choose CSS-pixel or device-pixel screenshot output. Learn why a high-DPI capture may be twice the viewport size and how to keep Windows visual comparisons consistent.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the viewport and device scale factor on Playwright’s browser context before opening the page, then choose whether the screenshot should use CSS pixels or device pixels. These settings work the same way in Playwright on Windows as they do on other host operating systems; Windows can affect rendering consistency, but there is no separate Windows-only setting for either value.

Set viewport and device scale factor when creating a context

Configure viewport and deviceScaleFactor in browser.newContext() before creating or navigating the page. This gives the page its intended emulated dimensions from the start.

As an Amazon Associate I earn from qualifying purchases.

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

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

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

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

The 1280 × 720 values are an example, not a Windows requirement. Playwright’s documented context viewport default is 1280 × 720, and deviceScaleFactor defaults to 1. See the BrowserType API and emulation guide.

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

Understand viewport, device scale factor, and screenshot scale

These settings control different things:

  • Viewport: The emulated visible page area, specified as width and height.
  • deviceScaleFactor: The emulated device pixel ratio (DPR), which determines how device pixels relate to CSS pixels.
  • Screenshot scale: Whether the output image uses CSS-pixel or device-pixel dimensions.

With scale: 'css', the screenshot has one image pixel per CSS pixel. With scale: 'device', it has one image pixel per device pixel. At a factor of 2, a 1280 × 720 CSS-pixel viewport can therefore produce a 2560 × 1440 device-pixel image. The actual output depends on the selected viewport, factor, and screenshot scale. The Page API documents the screenshot options.

#1 Best Overall
  • Choose scale: 'css' for an image sized to the CSS viewport.
  • Choose scale: 'device' when you need device-pixel detail and are prepared for a larger image.

Resize a page after creating it

For an existing page, use page.setViewportSize():

await page.setViewportSize({ width: 1280, height: 720 });

Set the size before navigation if the website responds to the initial viewport while loading. Playwright notes that resizing later changes the page and resets its screen size. If the emulated screen dimensions need to be controlled separately from the viewport, set both screen and viewport in the browser context options. See the Page API and BrowserType API.

Keep Windows screenshot comparisons consistent

Viewport and device scale factor are browser emulation settings, not Windows display-resolution controls. For visual regression tests, run baseline generation and comparisons in the same environment where possible. Playwright warns that rendering can vary with the host OS, browser version, settings, hardware, power source, and headless mode; changing any of these can affect pixel comparisons. See Playwright’s Visual comparisons guide.

Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.
  • Keep the OS and browser version consistent between baseline and test runs.
  • Use the same viewport, device scale factor, screenshot scale, and headless mode.
  • When a screenshot differs unexpectedly, check these conditions before treating the change as an application regression.

Troubleshooting unexpected screenshot dimensions

The image is twice the viewport width and height

Check whether the context uses deviceScaleFactor: 2 and the screenshot uses scale: 'device'. To capture at CSS-pixel dimensions, use scale: 'css' rather than changing the viewport.

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

The page initially renders at the wrong size

Set viewport in browser.newContext() before creating and navigating the page. A later page.setViewportSize() can resize the page, but it does not give the site the same initial viewport conditions.

Rank #3
15.6 Inch Laptop Computer, N4020, 4GB DDR4 RAM, 128GB eMMC,with Windows 11
  • EFFORTLESS EVERYDAY PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 Home system, delivering reliable, low-power efficiency for daily tasks like document editing, email, online classes, and web browsing
  • 15.6-INCH FULL HD DISPLAY: Enjoy immersive visuals on the 15.6" FHD (1920x1080) anti-glare screen with micro-edge bezels. Delivers clear details and comfortable viewing for long study sessions, working on spreadsheets, and video playback
  • RESPONSIVE MULTITASKING & STORAGE: Built with 4GB LPDDR4 RAM and 128GB eMMC storage for smooth daily essential use. Expand your storage by up to 1TB via the integrated TF card slot to easily store movies, photos, and working files
  • ADVANCED CONNECTIVITY: Outfitted with 2x Full-Featured Type-C ports for data transfer, fast charging, and dual-monitor output, alongside 2x USB 3.2 Gen1 ports and a 3.5mm audio jack for complete peripheral compatibility
  • LIGHTWEIGHT & SILENT OPERATION: Slim and portable for effortless travel or commuting. Features a 1MP HD webcam for remote meetings, 38Wh battery with 45W Type-C fast charging, and a fanless silent design for peaceful work environments.

The page layout changes after resizing

A resize can trigger responsive layout changes and resets the page’s screen size. If the site reads screen dimensions separately, configure the context’s screen and viewport values together.

Visual comparisons fail despite matching dimensions

Confirm that the baseline and current run use the same OS, browser version, browser settings, hardware conditions, and headless mode. Identical viewport dimensions alone do not guarantee identical rendering.

Rank #4
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

ScreenshotNeo can return an image or PDF from one API request. It accepts and removes cookie-consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, and failed loads are never billed. Its MCP server provides screenshot tools for AI agents, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Details and options are in the ScreenshotNeo API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

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

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$245.99
Bestseller No. 2
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$285.00

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.