How to Capture Screenshots Programmatically

Taking screenshots of websites programmatically is a common requirement for developers building monitoring tools, generating social media previews, creating PDF reports, or archiving web pages. In this guide, we’ll compare the most popular approaches and help you pick the right one for your use case.

Why capture screenshots programmatically?

There are many reasons you might need automated screenshots:

  • Social media previews — Generate Open Graph images for link sharing
  • Visual regression testing — Catch UI bugs before they ship
  • Web archiving — Preserve how a page looked at a specific point in time
  • Reporting — Include live website snapshots in PDF reports or dashboards
  • Competitor monitoring — Track visual changes to competitor websites

Approach 1: Use a Screenshot API

The simplest approach is to use a dedicated API. You send a URL and get back an image — no browser management, no infrastructure, no headless Chrome configuration.

bashcurl -X POST https://screenshot-api.pro/api/screenshot \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com"}' \ -o screenshot.png

Pros:

  • Zero infrastructure to manage
  • Works in any language (it’s just an HTTP request)
  • Handles edge cases like lazy loading, cookie banners, and SPAs
  • Scales automatically

Cons:

  • Costs money at high volumes (though most APIs have free tiers)
  • Adds a network dependency

Approach 2: Headless Chrome with Puppeteer

Puppeteer is a Node.js library that controls a headless Chrome browser. It gives you full control over the rendering pipeline.

javascriptconst puppeteer = require('puppeteer'); const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); await page.goto('https://example.com', { waitUntil: 'networkidle0' }); await page.screenshot({ path: 'screenshot.png', fullPage: true }); await browser.close();

Pros:

  • Full control over the browser
  • Free and open source
  • Can interact with pages (click buttons, fill forms) before capturing

Cons:

  • Requires managing Chrome/Chromium installations
  • Resource-intensive (each browser instance uses ~100MB+ RAM)
  • Tricky to deploy in containers and serverless environments
  • You need to handle timeouts, crashes, and zombie processes

Approach 3: Playwright

Playwright is Microsoft’s alternative to Puppeteer. It supports Chrome, Firefox, and WebKit, making it useful for cross-browser screenshots.

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

Pros:

  • Cross-browser support
  • Better auto-waiting than Puppeteer
  • Available in Python, Node.js, Java, and .NET

Cons:

  • Same infrastructure overhead as Puppeteer
  • Larger install size (downloads multiple browsers)

Comparison

Feature Screenshot API Puppeteer Playwright
Setup time Minutes Hours Hours
Infrastructure None Self-managed Self-managed
Languages Any (HTTP) Node.js Multi-language
Scaling Automatic Manual Manual
Cost Per-screenshot Server costs Server costs
Customization Medium Full Full
Reliability High Medium Medium

Which should you choose?

  • Use a Screenshot API if you want to get up and running fast, don’t want to manage infrastructure, or need reliability at scale. This is the best choice for most production use cases.

  • Use Puppeteer/Playwright if you need deep browser interaction (filling forms, clicking through flows) before capturing, or if you’re already running headless browsers for testing.

  • Use Playwright specifically if you need cross-browser screenshots or are working in Python/Java/.NET.

Getting started with Screenshot API

The fastest way to start capturing screenshots is with our API. You can be up and running in under a minute:

  1. Create a free account (100 screenshots/month)
  2. Copy your API key from the dashboard
  3. Make your first request:
bashcurl -X POST https://screenshot-api.pro/api/screenshot \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"url": "https://github.com", "width": 1280, "height": 800}' \ -o github.png

Check out the full documentation for all available parameters including full-page capture, custom viewports, and format options.