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

How to Capture a Responsive Website at Multiple Viewport Sizes with Playwright

Use a named viewport list to capture a page at mobile, tablet, desktop, or breakpoint-specific dimensions with Playwright. Learn when to use full-page images, device emulation, and visual assertions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define the viewport sizes you want to check, then capture the same page at each size. In a standalone Playwright script, loop over a named list of width-and-height pairs and save a screenshot for each. For a repeatable test suite, use named Playwright Test projects or parameterized tests so each image and result is tied to a specific viewport.

Capture the same page at several viewport sizes

This standalone TypeScript example opens a fresh browser context for each viewport and saves a labeled screenshot. The sample dimensions are examples, not universal breakpoints: choose sizes that match your site’s CSS breakpoints and the devices you care about.

As an Amazon Associate I earn from qualifying purchases.

import { chromium } from 'playwright';

const viewports = [
  { name: 'mobile', width: 390, height: 844 },
  { name: 'tablet', width: 768, height: 1024 },
  { name: 'desktop', width: 1440, height: 900 },
];

const browser = await chromium.launch();
try {
  for (const viewport of viewports) {
    const context = await browser.newContext({
      viewport: { width: viewport.width, height: viewport.height },
    });
    try {
      const page = await context.newPage();
      await page.goto('https://example.com');
      await page.screenshot({ path: `screenshots/home-${viewport.name}.png` });
    } finally {
      await context.close();
    }
  }
} finally {
  await browser.close();
}

Replace the example URL with the route under test. Create the screenshots directory before running the script, or change the output path to a directory that already exists. Each capture should use the same route and application state; otherwise, differences between files may reflect content changes rather than responsive layout.

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

Choose where to configure the viewport

Use the configuration level that fits how you run Playwright. The essential setting is an explicit viewport width and height for every capture.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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

Standalone script: context or page

The example sets the viewport when creating a browser context. That makes each context’s dimensions clear and keeps captures isolated. You can also change a page’s viewport with page.setViewportSize({ width, height }) when you want to reuse a page sequentially. Set the size before navigating if the site’s initial layout depends on viewport dimensions.

Playwright Test: named projects

When viewport sizes are part of a recurring suite, named projects make the configuration and results traceable. In playwright.config.ts, define projects with different use.viewport settings, then run the same test under each project:

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

export default defineConfig({
  projects: [
    { name: 'mobile', use: { viewport: { width: 390, height: 844 } } },
    { name: 'tablet', use: { viewport: { width: 768, height: 1024 } } },
    { name: 'desktop', use: { viewport: { width: 1440, height: 900 } } },
  ],
});

Project-level configuration is useful when many tests should run at each size. If only one test needs several sizes, parameterizing that test can keep the matrix local to the scenario.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Playwright Test: parameterized visual assertions

toHaveScreenshot() is a Playwright Test runner assertion. Use it in tests run by @playwright/test, rather than a standalone script that imports only Playwright. This example creates a distinct expected image name for each size:

import { test, expect } from '@playwright/test';

const viewports = [
  { name: 'mobile', width: 390, height: 844 },
  { name: 'tablet', width: 768, height: 1024 },
  { name: 'desktop', width: 1440, height: 900 },
];

for (const viewport of viewports) {
  test(`home page at ${viewport.name}`, async ({ page }) => {
    await page.setViewportSize({ width: viewport.width, height: viewport.height });
    await page.goto('https://example.com');
    await expect(page).toHaveScreenshot(`home-${viewport.name}.png`);
  });
}

Generate baselines deliberately and review them before accepting changes. Playwright’s screenshot assertion waits for consecutive screenshots to match before comparing with the baseline; it does not make the rendering environment irrelevant. Keep browser version, operating system, settings, hardware, power source, and headed or headless mode consistent where possible. Changes in those conditions can alter rendering even when the site code has not changed. See the Playwright visual comparisons documentation.

Viewport screenshots and full-page screenshots answer different questions

A normal page.screenshot() captures the visible viewport: what fits in the browser area at the selected width and height. This is the right choice for checking responsive behavior at a realistic screen height, such as whether a navigation menu, heading, or call to action fits above the fold.

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.

For a long-page record, use fullPage: true:

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

A full-page image captures the entire scrollable document as if it were displayed on a very tall screen. It is useful for reviewing overall page content, but it does not replace checking the page at realistic viewport heights. To compare how the page appears while a visitor scrolls or interacts, take viewport captures at each selected size and state.

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

Pick image scale and decide whether to emulate a device

CSS-pixel scale or device-pixel scale

Playwright’s screenshot scale option controls the output image resolution. scale: 'css' produces one screenshot pixel per CSS pixel, which keeps high-DPI captures smaller. scale: 'device' uses device pixels and is the documented default; on high-DPI displays, that can produce images twice as large or more.

await page.screenshot({ path: 'screenshots/home.png', scale: 'css' });

Custom viewport or device profile

A custom viewport controls the browser’s visible width and height. It does not, by itself, reproduce a physical phone or tablet. A Playwright device profile can also set emulated properties such as user agent, screen size, and touch capability. Device profiles are still emulation, not tests on real hardware. Consult the Playwright emulation guide for the available device settings.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

If you start with a device profile but need a custom viewport, apply your viewport after the profile so the custom width and height override the profile’s viewport:

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

Import the named profile from Playwright’s device descriptors when using this pattern. Keep the profile’s other emulated properties only if they suit the test; changing dimensions does not turn those properties into measurements from a real device.

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

Make captures comparable and useful

  • Choose sizes intentionally. Include widths around the breakpoints your layout actually uses, not just familiar device labels.
  • Keep the route and state consistent. Use the same page, content, login state, and relevant interactions for each size.
  • Label output by viewport. Names such as home-mobile.png make it easier to trace an image to its dimensions or test project.
  • Separate viewport checks from full-page records. A tall image can hide problems that appear at ordinary screen heights.
  • Stabilize the comparison environment. For screenshot assertions, run with consistent browser and machine conditions and inspect proposed baseline changes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common problems

The screenshot has the wrong dimensions

Confirm that both width and height are set in the context or page before navigation and capture. If using a device profile, check whether its viewport is overriding your intended dimensions; spread the profile first and set the custom viewport afterward.

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.

Images or layout are missing in the capture

Make sure navigation has reached the page state you intend to capture. If the page renders important content after navigation, wait for a meaningful selector or other application-specific ready condition before taking the screenshot. A fixed delay may be appropriate for a known animation or transition, but it can make tests slower and less reliable than waiting for the actual element.

Visual assertions fail intermittently

Look for changing content or animations as well as changes in the rendering environment. Keep browser version, operating system, settings, hardware, power source, and headed or headless mode consistent, and review the generated image before updating a baseline. A changed screenshot is evidence of a visual difference, not by itself proof that the responsive layout is broken.

The output file cannot be written

Check that the destination directory exists and that the process can write to it. For a set of files, ensure the generated names are distinct; otherwise a later capture can overwrite an earlier one.

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

Or skip the browser setup

If you only need a screenshot file rather than a Playwright test suite, ScreenshotNeo can return an image with one request. Its API supports PNG, JPEG, or WebP output, and accepts the same parameter names used by other screenshot APIs for easier switching. See the ScreenshotNeo API 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

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. It also provides an MCP server with screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does changing the viewport test a real phone?

No. A custom viewport changes the browser’s visible dimensions. Device profiles add emulated properties, but neither approach is a test on physical hardware.

Should I take full-page screenshots for responsive testing?

Use full-page captures for a record of the whole document; use viewport captures at realistic heights to assess what is visible on screen.

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.