This site is not affiliated with or endorsed by Cloudflare, Inc. It showcases deployable experiments across most Cloudflare products.
Browser Rendering

Screenshot API

Capture website screenshots with Cloudflare Browser Rendering - full-page or viewport PNG/JPEG screenshot API

Capture screenshots of any website from Cloudflare's edge network using Browser Rendering and Puppeteer.

API Reference

GET /screenshot

Captures a PNG screenshot of the specified URL.

Prop

Type

Example Request

curl "https://your-worker.workers.dev/screenshot?url=https://www.cloudflare.com" \
  --output screenshot.png

Success Response

Returns a PNG image with the following headers:

Content-Type: image/png
Cache-Control: public, max-age=60

Error Response

error string

Human-readable error message

code string

Error code indicating the failure type

{
  "error": "Missing or invalid query parameter: url",
  "code": "INVALID_URL"
}

Error Codes

  • 400 - Missing or invalid url parameter (not http/https)
  • 502 - Screenshot operation failed (navigation timeout, unreachable site, rendering error)

Implementation Details

The API uses the following configuration:

  • Viewport: 1280x800 pixels
  • Wait condition: networkidle0 (waits until network is idle)
  • Navigation timeout: 20 seconds
  • Image format: PNG

Use Cases

  • Capture visual snapshots of web pages from the edge
  • Generate thumbnails or previews for link-sharing tools
  • Archive how a page looked at a point in time
  • Learn Browser Rendering with Puppeteer on Workers

Limitations

  • Requires Browser Rendering enabled on your Cloudflare account
  • Fixed 1280×800 viewport; no custom dimensions in this experiment
  • 20-second navigation timeout; networkidle0 may fail on busy sites
  • Local development needs npx wrangler dev --remote

Use in your project

Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/screenshot-api.

DependenciesNoneBindingsBrowser RenderingPlatformWorkers runtime
import { ALLOWED_SCHEMES } from "../constants/defaults";export function validateUrl(input: string | undefined): string | null {  if (!input || typeof input !== "string") return null;  const trimmed = input.trim();  if (!trimmed) return null;  try {    const url = new URL(trimmed);    if (!ALLOWED_SCHEMES.includes(url.protocol as (typeof ALLOWED_SCHEMES)[number])) {      return null;    }    return url.href;  } catch {    return null;  }}

Deployment

Click the deploy button

Deploy to Cloudflare Workers

Enable Browser Rendering

This experiment requires Cloudflare Browser Rendering to be enabled on your account. Visit the Browser Rendering docs for setup instructions.

Deploy

Follow the deployment wizard to deploy the Worker to your Cloudflare account.

Local Development

cd apps/experiments/screenshot-api
npm install
npx wrangler dev --remote

Use --remote flag to access a real browser instance. Local development without this flag will not work as Browser Rendering requires Cloudflare infrastructure.

Test locally:

curl "http://localhost:8787/screenshot?url=https://www.cloudflare.com" \
  --output test.png

Cloudflare Features Used

On this page