# Playwright Screenshot: Full Page, Element

> Take screenshots with Playwright: page.screenshot for the viewport or full page, locator screenshots, JPEG quality, mask, style, scale and proxies, with sizes.

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / Playwright Screenshot: Full Page, Element

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

Guides · Nov 20, 2026 · 5 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![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.](https://quanticdata.io/blog/playwright-screenshot/hero.webp?v=20261120h)

On this page

- [The basics: viewport, full page, element, area](https://quanticdata.io/blog/playwright-screenshot/#the-basics-viewport-full-page-element-area)
- [JPEG and quality: the file sizes](https://quanticdata.io/blog/playwright-screenshot/#jpeg-and-quality-the-file-sizes)
- [Hide or cover parts of the page](https://quanticdata.io/blog/playwright-screenshot/#hide-or-cover-parts-of-the-page)
- [Retina, phone sizes and the buffer](https://quanticdata.io/blog/playwright-screenshot/#retina-phone-sizes-and-the-buffer)
- [Wait for the content before you capture](https://quanticdata.io/blog/playwright-screenshot/#wait-for-the-content-before-you-capture)
- [Screenshots through a proxy](https://quanticdata.io/blog/playwright-screenshot/#screenshots-through-a-proxy)
- [Quick reference](https://quanticdata.io/blog/playwright-screenshot/#quick-reference)

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.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=playwright-screenshot) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

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

```javascript
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();
```

| Call | Pixels | File 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 }` | 600x300 | 19248 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

```javascript
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, 1280x2549 | Bytes | Compared with PNG |
| --- | --- | --- |
| PNG (default) | 625254 | 100% |
| JPEG, quality 80 | 265959 | 43% |
| JPEG, quality 50 | 170638 | 27% |

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.

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=playwright-screenshot) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Retina, phone sizes and the buffer

```javascript
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:

```javascript
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](https://quanticdata.io/blog/how-to-use-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:

```javascript
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 });
```

| Network | Exit (ipinfo.io) | Page status | Full-page capture |
| --- | --- | --- | --- |
| Residential Basic | Independence, Kansas, US | 200 | 1280x2549, 625254 bytes |
| Residential Premium (port 8080) | Chattanooga, Tennessee, US | 200 | 1280x2549, 625254 bytes |
| Mobile (port 8080) | Houston, Texas, US | 200 | 1280x2549, 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](https://quanticdata.io/blog/playwright-proxy/), and the same idea in Puppeteer in [a proxy in Puppeteer](https://quanticdata.io/blog/how-to-use-a-proxy-in-puppeteer/).

## Quick reference

| Goal | Option |
| --- | --- |
| Whole page | `fullPage: true` |
| One element | `locator.screenshot({ path })` |
| A rectangle | `clip: { x, y, width, height }` |
| Smaller files | `type: 'jpeg', quality: 80` |
| Cover sensitive parts | `mask: [locator], maskColor` |
| Hide a banner | `style: 'selector { visibility: hidden; }'` |
| Stable captures | `animations: 'disabled', caret: 'hide'` |
| One pixel per CSS pixel | `scale: 'css'` |

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

### Sources & further reading

- [Playwright docs: Screenshots](https://playwright.dev/docs/screenshots)
- [Playwright API: page.screenshot](https://playwright.dev/docs/api/class-page#page-screenshot)
- [Playwright API: locator.screenshot](https://playwright.dev/docs/api/class-locator#locator-screenshot)
- [Playwright docs: Network, HTTP proxy](https://playwright.dev/docs/network#http-proxy)

## FAQ

Quick answers on playwright screenshot.

[Something else? Ask us](mailto:hello@quanticdata.io)

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

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=playwright-screenshot) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Related reading

- [Scraping Dynamic Web Pages in Python](https://quanticdata.io/blog/dynamic-web-scraping-python/): Guides · A dynamic page sends an almost empty HTML shell and fills it with JavaScript, so requests and Beautiful Soup see nothing. Look for the data first (a JSON block in a script tag or an API call), and render with Playwright or Selenium only when there is none. We ran all three on one page.
- [Playwright: Wait for Page to Load in Python](https://quanticdata.io/blog/playwright-wait-for-page-load/): Guides · goto() waits for the load event by default, but the data you want often arrives later. On a page that adds its content after a delay, every wait_until option returned with 0 items; waiting for the element itself returned all 10. The timings, the code and when to use each wait.
- [Playwright Test Timeout: Defaults and Config](https://quanticdata.io/blog/playwright-test-timeout/): Guides · Playwright Test stops a test after 30 seconds and an assertion after 5 seconds by default; actions and navigations have their own optional limits. We reproduced each timeout error on 20 November 2026 against a deliberately slow local server, then fixed each one with the setting made for it.

---

Source: https://quanticdata.io/blog/playwright-screenshot/ · Site index for AI: https://quanticdata.io/llms.txt
