Cloudflare Worker + Container + Durable Object — Cloud Headless Browser Service
X-API-Key header for authentication.?apiKey=xxx query param or X-API-Key header.
Capture a screenshot of a web page. Returns PNG or JPEG binary.
# Basic screenshot curl -X POST https://<worker>/api/screenshot \ -H "X-API-Key: <key>" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com"}' \ -o screenshot.png
| Parameter | Type | Description |
|---|---|---|
| url | string required | Target URL |
| width | number | Viewport width (default 1920) |
| height | number | Viewport height (default 1080) |
| fullPage | boolean | Capture full scrollable page |
| format | string | "png" (default) or "jpeg" |
| quality | number | JPEG quality 0-100 (only for jpeg) |
Extract content from a web page. Returns JSON with title and content.
# Scrape as plain text curl -X POST https://<worker>/api/scrape \ -H "X-API-Key: <key>" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com", "format": "text"}' # Response { "content": "Example Domain\nThis domain is for use...", "title": "Example Domain", "url": "https://example.com" }
| Parameter | Type | Description |
|---|---|---|
| url | string required | Target URL |
| format | string | "text" (default), "html", or "markdown" |
| waitFor | string | CSS selector to wait for before extraction |
| waitTimeout | number | Max wait time in ms (default 30000) |
Generate a PDF of a web page. Returns PDF binary.
# Generate PDF curl -X POST https://<worker>/api/pdf \ -H "X-API-Key: <key>" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com"}' \ -o output.pdf
| Parameter | Type | Description |
|---|---|---|
| url | string required | Target URL |
| format | string | "A4" (default), "Letter", or "Legal" |
| landscape | boolean | Landscape orientation (default false) |
| printBackground | boolean | Print background graphics (default true) |
Create a browser session for WebSocket CDP control.
# Create session curl -X POST https://<worker>/api/sessions \ -H "X-API-Key: <key>" # Response { "sessionId": "abc-123", "wsUrl": "/ws/sessions/abc-123" }
| Header | Type | Description |
|---|---|---|
| X-Session-Name | string | Custom session name (optional, auto-generated if omitted) |
Destroy a browser session and release resources.
curl -X DELETE https://<worker>/api/sessions/abc-123 \ -H "X-API-Key: <key>"
WebSocket endpoint for real-time CDP (Chrome DevTools Protocol) commands. Send JSON messages and receive responses.
# Connect with wscat wscat -c "wss://<worker>/ws/sessions/abc-123?apiKey=<key>" # Send CDP command > { "id": 1, "method": "Runtime.evaluate", "params": { "expression": "document.title" } } # Receive response < { "id": 1, "result": { "result": { "type": "string", "value": "Example Domain" } } }