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
| Need | Option |
|---|---|
| Dark mode | browser.newContext({ colorScheme: "dark" }) |
| Language | browser.newContext({ locale: "de-DE" }) |
| One element | page.locator("#hero").screenshot({ path: "hero.png" }) |
| Transparent background | page.screenshot({ omitBackground: true }) (PNG) |
| Clip a region | page.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.