Screenshot API
Capture screenshots of any website from the edge using Cloudflare Browser Rendering
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.pngSuccess Response
Returns a PNG image with the following headers:
Content-Type: image/png
Cache-Control: public, max-age=60Error 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 invalidurlparameter (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;
networkidle0may fail on busy sites - Local development needs
npx wrangler dev --remote
Deployment
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 --remoteUse --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.pngCloudflare Features Used
- Workers - Edge compute runtime
- Browser Rendering - Headless Chromium via Puppeteer
- Fetch API - Network requests within the browser