Playwright screenshot: full page and API alternative

By Mayur Gadakh · Published · Last updated

To take a screenshot with Playwright, launch Chromium, open the page and call page.screenshot(); add fullPage: true to capture the whole scrolling page. The code below runs as written. If you would rather not run a browser, one URLBooth API call returns the same screenshot.

How do I take a screenshot with Playwright?

Install Playwright and its browser with npm i playwright and npx playwright install chromium, then save this as screenshot.mjs and run node screenshot.mjs.

import { chromium } from "playwright";
​
const browser = await chromium.launch();
try {
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto("https://example.com", { waitUntil: "networkidle" });
await page.screenshot({ path: "screenshot.png", fullPage: true });
} finally {
await browser.close();
}

The result is a PNG of the full page at 1440 pixels wide. Remove fullPage: true to capture only the first screen.

Which Playwright screenshot options matter?

  • viewport sets the window size, which decides which responsive layout the page uses. deviceScaleFactor: 2 gives a sharper image at twice the pixels.
  • fullPage: true captures the whole scrollable page. clip captures a rectangle, and locator.screenshot() captures one element.
  • type is png or jpeg; quality applies to JPEG only.
  • waitUntil: "networkidle" waits for the network to go quiet. Playwright's own documentation discourages it for tests, and on pages that never stop loading (ads, polling, analytics) it can wait until the timeout, so a fixed wait or a specific element is often safer.

How do I get the same screenshot with one API call?

The URLBooth API opens the page in its own browser and returns the image. This Node.js script (Node 18 or later, no dependencies) saves the same full-page screenshot. It needs a Pro API key; see pricing.

URLBooth screenshot in Node.js
import { writeFile } from "node:fs/promises";
​
const response = await fetch("https://urlbooth.com/v1/screenshots", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.URLBOOTH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url: "https://example.com", device: "desktop", fullPage: true }),
signal: AbortSignal.timeout(60_000),
});
​
if (!response.ok) {
const { error } = await response.json();
throw new Error(`${error.code}: ${error.message}`);
}
​
await writeFile("screenshot.png", Buffer.from(await response.arrayBuffer()));

Cookie banners and ads are removed by default, there is no browser to install, and device takes one of 30 presets such as iphone-17-pro. Full-page images are limited to 10,000 pixels tall and 10 MB; an oversized page returns a 422 error rather than a cropped image.

Playwright or the API: which should I use?

Playwright yourselfURLBooth API
CostThe library is free. You pay for the servers or serverless time that run Chromium, and for the engineering time to run it.$20 per month (Pro) for up to 10,000 captures a day. There is no per-capture charge.
SpeedAbout 2 to 9 seconds per page in our tests, including starting the browser (3 sites, on a laptop).About 5 to 13 seconds in the same tests. The request travels over the internet and the browser starts for each capture.
MaintenanceYou keep the browser, its system libraries and fonts current, handle crashes, and limit concurrency. Cookie banners and ads are yours to remove.None to run. Cookie banners and ads are removed on a best-effort basis.
ControlFull: log in, click, run scripts, set headers, use any browser option.Public URLs only. Options: device, format, fullPage, frame, cleanup.
LimitsWhatever your machine can run.Output up to 10 MB, 45 seconds per request, 60 requests a minute and 10 at once.

Choose Playwright when you need to log in, click through a flow, run scripts before capturing, or keep pages inside your own network. Choose the API when you capture public pages and do not want to operate browsers. The full trade-offs are in screenshot API vs Puppeteer and Playwright.

Where to go next