Cloud Browser API

Cloudflare Worker + Container + Durable Object — Cloud Headless Browser Service

All endpoints require X-API-Key header for authentication.
WebSocket: pass ?apiKey=xxx query param or X-API-Key header.

POST /api/screenshot

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
ParameterTypeDescription
urlstring requiredTarget URL
widthnumberViewport width (default 1920)
heightnumberViewport height (default 1080)
fullPagebooleanCapture full scrollable page
formatstring"png" (default) or "jpeg"
qualitynumberJPEG quality 0-100 (only for jpeg)

POST /api/scrape

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"
}
ParameterTypeDescription
urlstring requiredTarget URL
formatstring"text" (default), "html", or "markdown"
waitForstringCSS selector to wait for before extraction
waitTimeoutnumberMax wait time in ms (default 30000)

POST /api/pdf

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
ParameterTypeDescription
urlstring requiredTarget URL
formatstring"A4" (default), "Letter", or "Legal"
landscapebooleanLandscape orientation (default false)
printBackgroundbooleanPrint background graphics (default true)

POST /api/sessions

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"
}
HeaderTypeDescription
X-Session-NamestringCustom session name (optional, auto-generated if omitted)

DELETE /api/sessions/:id

Destroy a browser session and release resources.

curl -X DELETE https://<worker>/api/sessions/abc-123 \
  -H "X-API-Key: <key>"

WS /ws/sessions/:id

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" } } }