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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How to Set the Device Scale Factor for Full-Page Screenshots in Playwright

Set deviceScaleFactor on the Playwright browser context, then choose screenshot scale and fullPage explicitly for predictable full-page output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set deviceScaleFactor when creating the browser context, then capture the page with fullPage: true. Set the screenshot’s scale separately: it controls whether output pixels correspond to CSS pixels or device pixels. For predictable dimensions, specify both settings explicitly.

Capture a full page at device scale factor 2

This runnable JavaScript example creates a context with a 1280 × 1024 CSS-pixel viewport and device scale factor 2, then saves a full-page PNG at device-pixel scale:

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: 1024 },
    deviceScaleFactor: 2,
  });
  const page = await context.newPage();

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

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

Replace the URL with the page you want. The viewport sets the emulated layout size in CSS pixels; the document’s rendered height determines how tall the full-page image is.

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

Where each setting belongs

Set deviceScaleFactor on the browser context

deviceScaleFactor configures the emulated device-pixel ratio (DPR). Pass it to browser.newContext(), not to page.screenshot(). Its documented default is 1. The viewport is a separate context setting, so specify both when capture dimensions need to be repeatable. See Playwright’s browser context options and its emulation guide.

Request the full page and choose screenshot scale

fullPage: true asks Playwright to capture the full scrollable page rather than just the visible viewport. The independent scale option determines the mapping from page units to output pixels:

  • scale: 'css' produces one output pixel per CSS pixel.
  • scale: 'device' produces one output pixel per device pixel. At a higher DPR, this can create a larger bitmap.

For Page.screenshot, the documented default scale is device. Set it explicitly rather than depending on a default. The full-page API and scale options are documented in Page.screenshot.

Choose the output scale you need

Setting Use it when Documented output mapping
scale: 'css' You want compact output measured in CSS pixels. One bitmap pixel per CSS pixel.
scale: 'device' You want device-pixel detail or high-DPI output. One bitmap pixel per device pixel; the bitmap may be larger at a higher DPR.

For example, with a 1280 CSS-pixel-wide viewport, scale: 'css' maps that CSS width to 1280 output pixels. With deviceScaleFactor: 2 and scale: 'device', the corresponding device-pixel width is 2560 pixels. A full-page capture’s height depends on the rendered document, not just the viewport height.

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.

Python example

Set the context option when creating the context and use Python’s snake_case spelling, full_page, for the full-page screenshot option:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        viewport={"width": 1280, "height": 1024},
        device_scale_factor=2,
    )
    page = context.new_page()
    page.goto("https://example.com")
    page.screenshot(
        path="full-page.png",
        full_page=True,
        scale="device",
    )
    browser.close()

Playwright’s Python API uses device_scale_factor for the context setting and full_page for full-page capture. See the Python browser context options and Python Page.screenshot API.

Set it in Playwright Test

For a test project, configure the viewport and device scale factor in the project’s use settings, then pass the desired scale when taking the screenshot:

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

export default defineConfig({
  use: {
    viewport: { width: 1280, height: 1024 },
    deviceScaleFactor: 2,
  },
});
await page.goto('https://example.com');
await page.screenshot({
  path: 'full-page.png',
  fullPage: true,
  scale: 'device',
});

Playwright’s emulation guide shows context settings in project configuration. If you use a device descriptor, explicit viewport values can override viewport values inherited from that descriptor. See Playwright emulation.

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

Avoid the screenshot scale default mismatch

Page.screenshot documents device as its default scale, while Playwright Test screenshot assertions document css as their default. Do not assume these APIs produce the same output size without an explicit setting. For a file capture with page.screenshot(), specify scale: 'css' or scale: 'device' according to your needs. The assertion options are documented in Playwright Test snapshot assertions.

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

Troubleshoot unexpected dimensions or content

  • The image is larger than expected: Check whether you selected scale: 'device'. With DPR above 1, device-pixel output is larger than CSS-pixel output. Use scale: 'css' for one bitmap pixel per CSS pixel.
  • Changing the screenshot scale has no effect on emulated DPR: These are separate controls. Set deviceScaleFactor on the context and scale on the screenshot options.
  • The image only shows the viewport: Confirm that the call uses fullPage: true in JavaScript or full_page=True in Python.
  • The output dimensions vary between captures: Explicitly set both the viewport and screenshot scale. Also account for changes in the rendered document height.
  • Lazy content or changing page content is missing or inconsistent: Full-page capture requests the full scrollable page, but the documented behavior does not establish identical results for every browser engine or for pages that change or load content lazily during capture. Validate the result in the browser and on the page you actually target.

Or skip the browser setup

For a single request, ScreenshotNeo can return a screenshot without setting up a Playwright browser context. One GET request can return PNG, JPEG, WebP, or PDF. The API’s options include full-page capture, device presets and arbitrary viewports, and retina scale; see the ScreenshotNeo API documentation for request parameters and formats.

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 and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf 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. Visit ScreenshotNeo or sign up for free.

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