Back to Blog
Tutorial February 16, 2026 · 7 min read

How to Capture Screenshots with an API in Node.js, Python, and Go

A step-by-step guide to capturing website screenshots programmatically. We'll cover the basics, add device presets and dark mode, then apply style themes — all with complete code examples you can copy-paste.

Prerequisites

You'll need two things:

  1. A PageBolt API keysign up free (takes 10 seconds, no credit card)
  2. An HTTP client in your language of choice (we'll use fetch, requests, and net/http)

Step 1: Your First Screenshot (cURL)

The fastest way to test is with cURL. This captures example.com as a PNG:

curl -X POST https://pagebolt.dev/api/v1/screenshot \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}' \
  -o screenshot.png

That's it. You now have a pixel-perfect screenshot of example.com. The default format is PNG at 1280×720 viewport.

Step 2: Node.js Example

import { writeFile } from 'fs/promises';

const res = await fetch('https://pagebolt.dev/api/v1/screenshot', {
  method: 'POST',
  headers: {
    'x-api-key': process.env.PAGEBOLT_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://your-site.com',
    format: 'webp',
    viewportDevice: 'macbook_pro_14',
    darkMode: true,
    blockBanners: true,
    blockAds: true,
  }),
});

const buffer = Buffer.from(await res.arrayBuffer());
await writeFile('screenshot.webp', buffer);
console.log(`Screenshot saved: ${buffer.length} bytes`);

Step 3: Python Example

import requests
import os

response = requests.post(
    'https://pagebolt.dev/api/v1/screenshot',
    headers={
        'x-api-key': os.environ['PAGEBOLT_KEY'],
        'Content-Type': 'application/json',
    },
    json={
        'url': 'https://your-site.com',
        'format': 'webp',
        'viewportDevice': 'macbook_pro_14',
        'darkMode': True,
        'blockBanners': True,
        'blockAds': True,
    },
)

with open('screenshot.webp', 'wb') as f:
    f.write(response.content)
print(f'Screenshot saved: {len(response.content)} bytes')

Step 4: Go Example

package main

import (
    "bytes"
    "encoding/json"
    "io"
    "net/http"
    "os"
)

func main() {
    body, _ := json.Marshal(map[string]any{
        "url":            "https://your-site.com",
        "format":         "webp",
        "viewportDevice": "macbook_pro_14",
        "darkMode":       true,
        "blockBanners":   true,
    })

    req, _ := http.NewRequest("POST",
        "https://pagebolt.dev/api/v1/screenshot",
        bytes.NewReader(body))
    req.Header.Set("x-api-key", os.Getenv("PAGEBOLT_KEY"))
    req.Header.Set("Content-Type", "application/json")

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()

    out, _ := os.Create("screenshot.webp")
    defer out.Close()
    io.Copy(out, resp.Body)
}

Step 5: Add Screenshot Styling

PageBolt can wrap your screenshot in beautiful style themes — macOS window frames, gradient backgrounds, shadows — in the same API call. Just add a style object:

{
  "url": "https://your-site.com",
  "format": "webp",
  "style": {
    "theme": "ocean"
  }
}

// Or customize individually:
{
  "url": "https://your-site.com",
  "style": {
    "frame": "macos",
    "background": "lavender",
    "shadow": "xl",
    "padding": 48,
    "borderRadius": 16
  }
}

There are 18 built-in themes to choose from. Preview them all in our interactive playground.

Advanced Options

The screenshot API supports 30+ parameters. Here are the most useful ones:

  • viewportDevice — 25+ presets: "iphone_15_pro", "macbook_pro_16", "galaxy_s24", etc.
  • selector — Capture a specific element: "#hero", ".pricing-table"
  • fullPage: true — Capture the entire scrollable page
  • darkMode: true — Force prefers-color-scheme: dark
  • blockBanners: true — Remove cookie consent popups
  • blockAds: true — Remove ads from the page
  • blockChats: true — Remove Intercom, Drift, etc.
  • delay: 2000 — Wait 2 seconds before capturing (for animations)
  • injectCss — Inject custom CSS before capture
  • extractMetadata: true — Get page title, OG tags, etc. alongside the screenshot

See the full API reference for all options.

Try it right now — no signup

Capture 5 free screenshots in our sandbox, or sign up for 100/month on all 7 APIs.

Frequently Asked Questions

How do I take a screenshot with an API?+

Make a POST request to a screenshot API with the target URL in the body. For PageBolt: send a JSON body with {"url": "https://example.com"} to https://pagebolt.dev/api/v1/screenshot with your API key in the x-api-key header. The API returns the screenshot as a binary image. No SDK required — any HTTP client in any language works.

What is the best screenshot API for Node.js?+

PageBolt is a top choice for Node.js developers. It requires zero dependencies — just use the built-in fetch API (Node 18+). You get 30+ parameters, 25+ device presets, dark mode, ad blocking, and screenshot styling in one API call. The free tier includes 100 requests/month with no credit card required.

Can I capture screenshots of pages that require login?+

Yes. You can pass cookies or authorization headers in the API request to authenticate. For more complex flows (filling login forms, clicking buttons), use PageBolt's Sequence Builder to navigate through the login flow before capturing. See the Sequences documentation for details.

Start capturing screenshots today

Free API key — 100 requests/month, all 7 APIs, no credit card.

Sign Up Free