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 desk3 min

How to Take a Playwright Screenshot with a Custom Device Scale Factor

Configure Playwright’s emulated DPR on the browser context, then choose whether the screenshot uses CSS pixels or device pixels.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set deviceScaleFactor on the browser context before creating the page, then choose the screenshot’s output scale. Use scale: 'device' for device-pixel output at the emulated device pixel ratio, or scale: 'css' for one output pixel per CSS pixel.

Capture a screenshot with a custom device scale factor

In a standalone Playwright script, configure the context before creating a page or navigating. This TypeScript example sets a 1280 × 720 CSS-pixel viewport and emulates a device scale factor of 2:

As an Amazon Associate I earn from qualifying purchases.

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

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 browser.close();

The context option establishes the emulated device pixel ratio (DPR). The screenshot option controls whether the resulting image uses CSS pixels or device pixels. Set both deliberately: changing the DPR does not mean the output must use device-pixel dimensions.

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

Choose the screenshot output scale

Screenshot option Output pixel grid When to use it
scale: 'device' One output pixel per emulated device pixel. At DPR 2, a 1280 × 720 CSS-pixel viewport corresponds to 2560 × 1440 device pixels. Use when you need a high-DPI image matching the emulated device-pixel grid.
scale: 'css' One output pixel per CSS pixel. For the example viewport, that corresponds to 1280 × 720 pixels. Use when you want compact output dimensions based on CSS pixels, regardless of the larger emulated DPR.

Playwright’s screenshot API defaults to device. Specify css explicitly when you want CSS-pixel output. Actual image dimensions also depend on the viewport and what you capture, so treat the dimensions above as the example’s viewport-sized output rather than a promise for every screenshot.

#1 Best Overall
Sale
Motorola Moto g - 2026 | Unlocked | Made for US 4/128GB | 50MP Camera | Pantone Slipstream, Cellular_Phone
  • Universal unlocked. Compatible with all major U.S. carriers, including Verizon, AT&T, T-Mobile and other prepaid carriers.
  • Super-bright, super-smooth 6.7" display. See your screen clearly even outdoors in sunlight, and enjoy seamless views with a fast-refreshing 120Hz display.*
  • AI-powered camera system. Take stunning photos in any light with the 50MP camera**, look your best with a 32MP selfie cam*****, and capture extreme close-ups.
  • Superfast 5G performance. Unleash your entertainment at 5G speed*** with the MediaTek Dimensity 6300 chipset and up to 12GB of RAM with RAM Boost****.
  • Long-lasting battery + TurboPower charging. Power through day after day with a 5200mAh battery, then get hours of power in just minutes.****

Set the factor in Playwright Test

For a project-wide default, configure the use options in the Playwright Test configuration:

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

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

For a narrower test scope, set the corresponding use option with test.use() in the relevant scope. In either case, the context must receive the device scale factor before the page is created and captured. Keep the screenshot call’s scale choice explicit if the expected output grid matters to your test.

Rank #2
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black | Large AMOLED, High-Res Camera, Durable Design, Super Fast Charging, Expandable Storage, Circle to Search, 2025
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Use a device preset when it fits

Playwright’s device emulation supports device presets as well as explicit viewport configuration. A preset can provide device settings together; if you spread a preset and want to override its viewport, put your viewport override after the spread so your chosen dimensions take precedence. The documented factor of 2 is an example, not a universal recommendation: select the factor and viewport that match the rendering conditions you need to reproduce.

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

Keep visual regression screenshots comparable

A matching device scale factor alone does not guarantee pixel-identical screenshots. Playwright identifies the operating system, browser version, settings, hardware, power source, and headless mode as sources of rendering variation. For visual regression baselines, generate and compare screenshots in a consistent browser and execution environment, and keep the viewport, context options, and screenshot scale consistent as well.

Rank #3
Samsung Galaxy A16 5G 128GB Cell Phone, Unlocked Android Smartphone, Large AMOLED Display, Durable Design, Super Fast Charging, Expandable Storage, US Version, 2025, Blue Black (Renewed)
  • Charger NOT Included, 6.7" Super AMOLED FHD+, 90Hz Refresh Rate, 385 ppi, 800 nits (HBM), 1080x2340px, 5000mAh Battery
  • 128GB, 4GB RAM, microSDXC, Exynos 1330 (5nm), Octa-Core, Mali-G68 MP2 or Mali-G57 MC2 GPU
  • Rear Camera: 50MP, f/1.8 (wide) + 5MP, f/2.2 (ultrawide) + 2MP, f/2.4 (macro), LED flash, panorama, HDR; Front Camera: 13MP, f/2.0, Android 14, up to 6 major Android upgrades, One UI 6.1
  • 3G: HSDPA 850/900/1700(AWS)/1900/2100; 4G LTE: 1/2/3/4/5/7/12/13/14/20/25/26/28/29/30/38/39/40/41/48/66/71, 5G: 2/5/25/41/66/71/77/78 SA/NSA/Sub6/mmWave - Nano-SIM + eSIM
  • US Model – Global Connectivity – Compatible with Most GSM Carriers like T-Mobile, AT&T, MetroPCS, etc. Will Also work with CDMA Carriers Such as Verizon, Straight Talk.

Troubleshooting

  • The image is twice the viewport dimensions. With a factor of 2 and scale: 'device', one CSS pixel maps to two output pixels in each dimension. Choose scale: 'css' if you need output dimensions on the CSS-pixel grid.
  • The image has the expected dimensions but not the expected rendering. Check that deviceScaleFactor was applied to the browser context before page creation and navigation, and confirm that the selected viewport is the one used for capture.
  • The screenshot does not match a visual baseline. Keep the browser version and execution environment consistent; OS, hardware, settings, power source, and headless mode can affect rendering.
  • A device or scale option behaves differently in another browser engine or Playwright release. The behavior may depend on engine and version. Confirm the installed Playwright version and consult documentation for that version and engine before assuming Chromium, Firefox, and WebKit behave identically.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need an image from a URL rather than a Playwright-controlled test, ScreenshotNeo offers a screenshot API with viewport and retina-scale options. The API can return PNG, JPEG, WebP, or PDF; it does not replace Playwright when you need to test or automate a browser context.

For example, request a WebP screenshot of a page with one GET call:

Best Value
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.
Rank #4
Sale
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue | Large AMOLED, High-Res Camera, Durable Design, Super Fast Charging, Expandable Storage, Circle to Search, 2025
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
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 API documentation for request options. It removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed; and an MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000.

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

Sign up for ScreenshotNeo’s free plan.

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 *

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.

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.