Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

Playwright screenshots: viewport, full page, element, JPEG quality and mask

Playwright screenshot options measured on one page: the viewport PNG at 1280x720 was 125930 bytes, the full page PNG at 1280x2549 was 625254 bytes, the same full page as JPEG at quality 80 was 265959 bytes and at quality 50 was 170638 bytes; one product card captured with locator.screenshot was 22435 bytes.
Playwright screenshot options measured on one page: the viewport PNG at 1280x720 was 125930 bytes, the full page PNG at 1280x2549 was 625254 bytes, the same full page as JPEG at quality 80 was 265959 bytes and at quality 50 was 170638 bytes; one product card captured with locator.screenshot was 22435 bytes.

To take a screenshot with Playwright, call await page.screenshot({ path: 'shot.png' }) for the visible viewport, add fullPage: true for the whole scrollable page, or call locator.screenshot() to capture one element. Options set the format (type: 'jpeg', quality), cover parts of the page (mask) and the pixel scale.

We ran every snippet below on 20 November 2026 with Playwright 1.61.1, Chromium 149 and Node.js 22 on Windows 11, against books.toscrape.com, a sandbox made for scraping practice, and read each file's size and dimensions afterwards.

The basics: viewport, full page, element, area

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
await page.goto('https://books.toscrape.com/', { waitUntil: 'load' });

await page.screenshot({ path: 'shots/viewport.png' });
await page.screenshot({ path: 'shots/full.png', fullPage: true });
await page.locator('article.product_pod').first().screenshot({ path: 'shots/element.png' });
await page.screenshot({ path: 'shots/clip.png', clip: { x: 0, y: 0, width: 600, height: 300 } });
await browser.close();
CallPixelsFile size
page.screenshot()1280x720 (the viewport)125930 bytes
page.screenshot({ fullPage: true })1280x2549 (the whole page)625254 bytes
locator.screenshot()195x371 (one product card)22435 bytes
clip: { x: 0, y: 0, width: 600, height: 300 }600x30019248 bytes

The viewport you set in newPage decides the width of every capture. locator.screenshot() scrolls the element into view and crops to its box, which is the cleanest way to capture a chart, a price box or a product card.

JPEG and quality: the file sizes

await page.screenshot({ path: 'shots/full-q80.jpg', fullPage: true, type: 'jpeg', quality: 80 });
await page.screenshot({ path: 'shots/full-q50.jpg', fullPage: true, type: 'jpeg', quality: 50 });
Full page, 1280x2549BytesCompared with PNG
PNG (default)625254100%
JPEG, quality 8026595943%
JPEG, quality 5017063827%

For archives of thousands of pages, JPEG at 80 cut the file to less than half. quality only applies to JPEG; PNG is lossless and has no quality setting.

Hide or cover parts of the page

  • mask: [page.locator('.price_color')] paints a box over every match. With maskColor: '#4B3FD6' each price on our capture became a solid violet bar; use it for names, prices or anything you must not store.
  • style: '.page_inner .side_categories { visibility: hidden; }' injects CSS for the capture only. The category sidebar was blank in the file and back on the page afterwards. Good for cookie banners and chat widgets.
  • animations: 'disabled' and caret: 'hide' stop CSS animations and hide the text cursor during the capture, so repeated captures are easier to compare.

Retina, phone sizes and the buffer

const ctx2 = await browser.newContext({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 2 });
const p2 = await ctx2.newPage();
await p2.goto('https://books.toscrape.com/');
await p2.screenshot({ path: 'shots/retina.png' });                  // 2560x1440, 367341 bytes
await p2.screenshot({ path: 'shots/retina-css.png', scale: 'css' }); // 1280x720, 125930 bytes

const { devices } = await import('playwright');
const ctxM = await browser.newContext({ ...devices['iPhone 13'] });
const pm = await ctxM.newPage();
await pm.goto('https://books.toscrape.com/');
await pm.screenshot({ path: 'shots/iphone.png' });                  // 1170x1992, 127121 bytes

const buf = await page.screenshot();                                // no path: a Buffer
console.log(buf.length, buf.toString('base64').length);             // 129571 172764

With deviceScaleFactor: 2 each CSS pixel becomes two, so the file doubles in both directions; scale: 'css' keeps one pixel per CSS pixel. Device presets such as iPhone 13 set a phone viewport and scale in one line: our capture came out 1170x1992. Without path, screenshot() returns a Buffer you can upload or embed as base64.

Wait for the content before you capture

A screenshot shows the page at that instant. On quotes.toscrape.com/js/ the quotes are written by JavaScript, so we waited for them first:

await page.goto('https://quotes.toscrape.com/js/', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('div.quote');
console.log('quotes rendered', await page.locator('div.quote').count());   // quotes rendered 10
await page.screenshot({ path: 'shots/js-page.png', fullPage: true });       // 1280x1698

Wait for the element that proves the data is there, not a fixed time. Waits are covered in more depth in Playwright for scraping.

Screenshots through a proxy

Pages can look different by country: prices, languages, banners, search results. To capture what a visitor in a given place sees, give the browser context a proxy. Playwright takes the username and password as separate fields:

const ctx = await browser.newContext({
  proxy: { server: 'http://residentialboson.quanticdata.io:10000', username: 'USER-type-residential-country-us-session-pw01-lifetime-30', password: 'PASS' },
  viewport: { width: 1280, height: 720 },
});
const p = await ctx.newPage();
await p.goto('https://books.toscrape.com/', { waitUntil: 'load' });
await p.screenshot({ path: 'shots/proxy-basic.png', fullPage: true });
NetworkExit (ipinfo.io)Page statusFull-page capture
Residential BasicIndependence, Kansas, US2001280x2549, 625254 bytes
Residential Premium (port 8080)Chattanooga, Tennessee, US2001280x2549, 625254 bytes
Mobile (port 8080)Houston, Texas, US2001280x2549, 625254 bytes

All three captures were byte for byte the same size as the direct one, because this test page is the same everywhere. On pages that change by location, the capture is where you see the difference. One context per proxy keeps the sessions apart; more on the proxy object in Playwright proxy setup, and the same idea in Puppeteer in a proxy in Puppeteer.

Quick reference

GoalOption
Whole pagefullPage: true
One elementlocator.screenshot({ path })
A rectangleclip: { x, y, width, height }
Smaller filestype: 'jpeg', quality: 80
Cover sensitive partsmask: [locator], maskColor
Hide a bannerstyle: 'selector { visibility: hidden; }'
Stable capturesanimations: 'disabled', caret: 'hide'
One pixel per CSS pixelscale: 'css'

For location-dependent captures, our residential proxies and mobile proxies plug into the context's proxy field as shown (there is a Residential Basic free trial). Our cloud browser is open for the waitlist.

Sources & further reading

FAQ

Quick answers on playwright screenshot.

Something else? Ask us

How do I take a screenshot in Playwright?

await page.screenshot({ path: 'shot.png' }) saves the visible viewport. Add fullPage: true for the whole page; on our test page that grew the capture from 1280x720 to 1280x2549.

How do I take a screenshot of one element in Playwright?

Call screenshot() on a locator: await page.locator('article.product_pod').first().screenshot({ path: 'card.png' }). Playwright scrolls to the element and crops to it; our product card came out at 195x371.

How do I make Playwright screenshots smaller?

Save JPEG with a quality: type: 'jpeg', quality: 80. Our full-page PNG of 625254 bytes became 265959 bytes at quality 80 and 170638 at quality 50. Capturing an element or a clip instead of the full page helps too.

How do I hide elements in a Playwright screenshot?

Use mask: [locator] to paint over them (with maskColor for the colour), or style to inject CSS such as visibility: hidden for that capture only.

Where does Playwright save screenshots?

Where the path option says, relative to the folder you run Node from. Without path, screenshot() returns a Buffer and writes nothing.

How do I take Playwright screenshots through a proxy?

Create a context with proxy: { server, username, password } and take the screenshot in a page of that context. We captured the same page through residential and mobile proxies in three US cities, each with status 200.

Capture pages as visitors in other countries see them

Residential and mobile proxies for Playwright contexts, with country targeting and sticky sessions.

Related reading