October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Redmond desk5 min

How to Capture a Website Screenshot with a Fixed Viewport in Playwright on Windows

Set Playwright's viewport before navigation on Windows, then capture the visible page with page.screenshot(). Learn configuration scope, full-page capture, scale, and baseline tips.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the viewport before navigating, then capture the page. In Playwright on Windows, create a browser context with a fixed viewport, open a page, navigate to the URL, and call page.screenshot(). The same Playwright APIs apply across operating systems; there is no separate Windows-only screenshot method.

Capture a screenshot at a fixed viewport

This runnable JavaScript example uses Playwright’s library. It configures a 1280-by-720-pixel viewport before the page loads and saves the visible area as a PNG:

As an Amazon Associate I earn from qualifying purchases.

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

(async () => {
  const browser = await chromium.launch();
  try {
    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: 'screenshot.png' });
  } finally {
    await browser.close();
  }
})();

Install the Playwright package in your project if it is not already installed, and ensure the browser binaries Playwright uses are installed. Run the script from Windows Terminal, PowerShell, or another shell in the project directory. Replace the example URL and filename as needed.

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

The important order is viewport, navigation, screenshot. Playwright warns that changing viewport size after navigation can affect sites that react to viewport changes. The Page API recommends setting it before navigating.

#1 Best Overall

Choose where to configure the viewport

Use the narrowest scope that fits your job: one page, a browser context, or a Playwright Test project or test.

Browser context: a consistent setting for pages in a context

The example above sets viewport in browser.newContext(). This is a good default for scripts that create one or more pages needing the same viewport. Context-level configuration also allows you to set related emulation options, such as screen and deviceScaleFactor; see the emulation guide.

Page API: set it explicitly before navigation

You can create a page, set its viewport, and only then navigate:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const page = await context.newPage();
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });

page.setViewportSize() resets the screen size. If your test needs deliberate control of both screen and viewport, set those through the browser context instead of relying on this page-level method. The Page API documents this distinction.

Playwright Test: configure a project or test

For a project-wide default, put the viewport in the project’s use configuration:

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

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

To set it for a particular test file or group, use test.use():

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

test.use({ viewport: { width: 1280, height: 720 } });

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

These configuration patterns are documented in Playwright’s emulation guide. Choose project or test scope when multiple tests should share the setting; choose a context or page setting in a standalone script.

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

Decide what the screenshot should include

Visible viewport or full scrollable page

By default, page.screenshot({ path: 'screenshot.png' }) captures the currently visible viewport. Set fullPage: true to capture the full scrollable page:

await page.screenshot({ path: 'full-page.png', fullPage: true });

A full-page image is not a fixed-height viewport capture: its height expands to include the page’s scrollable content. If the goal is to compare a specific screen-sized layout, leave fullPage off.

CSS-pixel dimensions or device-pixel detail

The scale option controls output density. Use scale: 'css' for one output image pixel per CSS pixel. Use scale: 'device' for device-pixel output, which may be twice as large or more on high-DPI displays:

await page.screenshot({ path: 'css-scale.png', scale: 'css' });
await page.screenshot({ path: 'device-scale.png', scale: 'device' });

The viewport dimensions remain CSS pixels; scale determines the screenshot’s pixel density. For a baseline whose image dimensions should correspond directly to the CSS viewport, use 'css'. For higher-density detail, use 'device'. Playwright’s screenshot options, including supported image formats, are listed in the Page API.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Format and other capture controls

The filename extension determines the image format when Playwright can infer it. Supported screenshot types include PNG, JPEG, and WebP; PNG is the default. Options such as animations: 'disabled', caret: 'hide', clip, and style can control animations, the text caret, a crop, or applied CSS. Add them only when the capture requires those adjustments; they do not set the viewport size.

Rank #3
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage | LPDDR4 RAM, 180° Lay-Flat, Dual-Band WiFi, Type-C PD Fast Charging, Thin & Lightweight for Students, Home & Office, Gray
  • 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

Use the same environment for repeatable captures

A fixed viewport makes the layout dimensions more consistent, but it does not guarantee pixel-identical screenshots across machines. Playwright notes that rendering can vary with the host operating system, browser version, settings, hardware, power source, and headless mode. For visual regression baselines, run captures in the same environment as the baseline and keep the Playwright/browser versions and execution setup stable. See Playwright’s visual comparisons guidance.

Windows does not require a different viewport API. The practical reproducibility concern is whether the Windows machine running the capture matches the environment used to create and update its baseline.

Common problems and fixes

  • The page has the wrong responsive layout: Set the viewport in the context or call page.setViewportSize() before page.goto(). Resizing after navigation can trigger different site behavior.
  • The image is taller than the viewport: Check that you did not set fullPage: true. Omit it, or set it to false, to capture only the visible viewport.
  • Image pixel dimensions do not match the CSS dimensions: Check the scale option. 'device' uses device pixels; 'css' uses one image pixel per CSS pixel.
  • The screenshot differs from a baseline on another machine: Match the host environment and browser version, not just viewport width and height. Rendering can vary across operating systems, hardware, settings, and headless mode.
  • Changing the page viewport also changes the screen setting: page.setViewportSize() resets screen size. Configure screen and viewport together through browser.newContext() if both matter.

Or skip the browser setup

If you need a screenshot without installing or managing Playwright in your Windows project, ScreenshotNeo offers a website screenshot API. One GET request can return an image or PDF. Its clean-shot steps can accept cookie or consent banners and remove supported consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with the result identified in response headers. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents.

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

For example, using cURL from a shell, replace YOUR_API_KEY with your key and change the target URL as needed:

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 documentation for API details and options. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo.

Frequently Asked Questions

Does Playwright use a different fixed-viewport screenshot API on Windows?

No. The viewport and screenshot APIs are general Playwright APIs; the same flow applies on Windows.

Does setting the viewport guarantee identical screenshots on every machine?

No. Browser and host environment differences can change rendering even when viewport dimensions match.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
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.