Tutorial · Node.js & Python

Screenshots with Playwright

Playwright runs Chromium, Firefox and WebKit from one API, which makes it great for screenshots across browsers.

Updated October 1, 2026 · 1 min read

Node.js

npm install playwright && npx playwright install chromium
import { chromium, devices } from "playwright";

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
await page.goto("https://example.com");
await page.screenshot({ path: "example.png", fullPage: true });

// Mobile
const iphone = await browser.newContext({ ...devices["iPhone 13"] });
const mobile = await iphone.newPage();
await mobile.goto("https://example.com");
await mobile.screenshot({ path: "iphone.png" });
await browser.close();

Python

pip install playwright && playwright install chromium
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 1280, "height": 800})
    page.goto("https://example.com")
    page.screenshot(path="example.png", full_page=True)
    browser.close()

Useful options

NeedOption
Dark modebrowser.newContext({ colorScheme: "dark" })
Languagebrowser.newContext({ locale: "de-DE" })
One elementpage.locator("#hero").screenshot({ path: "hero.png" })
Transparent backgroundpage.screenshot({ omitBackground: true }) (PNG)
Clip a regionpage.screenshot({ clip: { x: 0, y: 0, width: 800, height: 400 } })

Playwright’s geolocation option only changes the JavaScript geolocation API, not the IP address. To see a site as visitors in another country do, you need an IP in that country: the screenshot from another country tool or the API’s ip_country_code.

Frequently asked questions

Can Playwright take screenshots in Safari?

It can take screenshots with WebKit, the engine behind Safari, on Linux, macOS and Windows. Rendering is close to Safari but not identical.

How do I compare screenshots in tests?

Use Playwright Test's expect(page).toHaveScreenshot(). The first run stores a baseline image; later runs fail if the page differs beyond a threshold.

Screenshot API

Take screenshots from your code

screenshotbase renders any website in a real browser and returns the image: full page or viewport, any device size, retina, from 100+ countries, with cookie banners and ads hidden.

Read the docs

300 free screenshots every month. No credit card required.

GET https://api.screenshotbase.com/v1/take?url=https://example.com&full_page=true

# Response: the image (PNG, JPG, WebP or GIF)
curl -G "https://api.screenshotbase.com/v1/take" \
  --data-urlencode "url=https://example.com" \
  -d viewport_width=1280 -d viewport_height=800 \
  -d format=png \
  -H "apikey: YOUR-API-KEY" \
  -o screenshot.png

Keep reading

Start using our Screenshot API for free today!

Get 300 requests / month for free