cloudflare-browser-rendering
Cloudflare Browser Rendering with Puppeteer/Playwright. Use for screenshots, PDFs, web scraping, or encountering rendering errors, timeout issues, memory exceeded.
What this skill does
# Cloudflare Browser Rendering - Complete Reference Production-ready knowledge domain for building browser automation workflows with Cloudflare Browser Rendering. **Status**: Production Ready ✅ **Last Updated**: 2025-11-25 **Dependencies**: cloudflare-worker-base (for Worker setup) **Latest Versions**: @cloudflare/[email protected], @cloudflare/[email protected], [email protected], @cloudflare/[email protected] --- ## Table of Contents 1. [Quick Start (5 minutes)](#quick-start-5-minutes) 2. [Browser Rendering Overview](#browser-rendering-overview) 3. [Puppeteer API Reference](#puppeteer-api-reference) 4. [Playwright API Reference](#playwright-api-reference) 5. [Session Management](#session-management) 6. [Common Patterns](#common-patterns) 7. [Pricing & Limits](#pricing--limits) 8. [Known Issues Prevention](#known-issues-prevention) 9. [Production Checklist](#production-checklist) --- ## Quick Start (5 minutes) ### 1. Add Browser Binding **wrangler.jsonc:** ```jsonc { "name": "browser-worker", "main": "src/index.ts", "compatibility_date": "2023-03-14", "compatibility_flags": ["nodejs_compat"], "browser": { "binding": "MYBROWSER" } } ``` **Why nodejs_compat?** Browser Rendering requires Node.js APIs and polyfills. ### 2. Install Puppeteer ```bash bun add @cloudflare/puppeteer ``` ### 3. Take Your First Screenshot ```typescript import puppeteer from "@cloudflare/puppeteer"; interface Env { MYBROWSER: Fetcher; } export default { async fetch(request: Request, env: Env): Promise<Response> { const { searchParams } = new URL(request.url); const url = searchParams.get("url") || "https://example.com"; // Launch browser const browser = await puppeteer.launch(env.MYBROWSER); const page = await browser.newPage(); // Navigate and capture await page.goto(url); const screenshot = await page.screenshot(); // Clean up await browser.close(); return new Response(screenshot, { headers: { "content-type": "image/png" } }); } }; ``` ### 4. Deploy ```bash bunx wrangler deploy ``` Test at: `https://your-worker.workers.dev/?url=https://example.com` **CRITICAL:** - Always pass `env.MYBROWSER` to `puppeteer.launch()` (not undefined) - Always call `browser.close()` when done (or use `browser.disconnect()` for session reuse) - Use `nodejs_compat` compatibility flag --- ## When to Load References **Load immediately when user mentions**: - `puppeteer-api.md` → "API reference", "Puppeteer methods", "Browser class", "Page methods", "complete API" - `patterns.md` → "examples", "how to", "screenshot", "PDF", "scraping", "automation", "form filling" - `session-management.md` → "sessions", "hibernation", "connection pooling", "state management", "Durable Objects" - `pricing-and-limits.md` → "cost", "pricing", "limits", "quotas", "billing", "rate limits" - `common-errors.md` → errors, debugging, "not working", troubleshooting, "issue #4", "issue #5", "issue #6" - `puppeteer-vs-playwright.md` → "Playwright", "comparison", "which library", "differences" **Load proactively when**: - Building new automation → Load `patterns.md` - Debugging errors → Load `common-errors.md` - Optimizing costs → Load `pricing-and-limits.md` - Managing sessions → Load `session-management.md` - Need complete API → Load `puppeteer-api.md` --- ## Browser Rendering Overview ### What is Browser Rendering? Cloudflare Browser Rendering provides headless Chromium browsers running on Cloudflare's global network. Use familiar tools like Puppeteer and Playwright to automate browser tasks: - **Screenshots** - Capture visual snapshots of web pages - **PDF Generation** - Convert HTML/URLs to PDFs - **Web Scraping** - Extract content from dynamic websites - **Testing** - Automate frontend tests - **Crawling** - Navigate multi-page workflows ### Two Integration Methods | Method | Best For | Complexity | |--------|----------|-----------| | **Workers Bindings** | Complex automation, custom workflows, session management | Advanced | | **REST API** | Simple screenshot/PDF tasks | Simple | **This skill covers Workers Bindings** (the advanced method with full Puppeteer/Playwright APIs). ### Puppeteer vs Playwright | Feature | Puppeteer | Playwright | |---------|-----------|------------| | **API Familiarity** | Most popular | Growing adoption | | **Package** | `@cloudflare/[email protected]` | `@cloudflare/[email protected]` | | **Session Management** | ✅ Advanced APIs | ⚠️ Basic | | **Browser Support** | Chromium only | Chromium only (Firefox/Safari not yet supported) | | **Best For** | Screenshots, PDFs, scraping | Testing, frontend automation | **Recommendation**: Use Puppeteer for most use cases. Playwright is ideal if you're already using it for testing. --- ## Puppeteer API Reference **Core classes for browser automation**: 1. **Core Functions** - `launch()`, `connect()`, `sessions()`, `history()`, `limits()` 2. **Browser API** - `newPage()`, `sessionId()`, `close()`, `disconnect()`, `createBrowserContext()` 3. **Page API** - `goto()`, `screenshot()`, `pdf()`, `content()`, `setContent()`, `evaluate()`, `waitForSelector()`, `type()`, `click()` **Quick Example:** ```typescript const browser = await puppeteer.launch(env.MYBROWSER); const page = await browser.newPage(); await page.goto("https://example.com"); const screenshot = await page.screenshot({ fullPage: true }); await browser.close(); ``` **Load `references/puppeteer-api.md` when implementing browser automation, scraping, debugging Puppeteer-specific issues, or needing complete API signatures and method details.** --- ## Playwright API Reference Playwright provides a similar API to Puppeteer with slight differences. ### Installation ```bash bun add @cloudflare/playwright ``` ### Basic Example ```typescript import { env } from "cloudflare:test"; import { chromium } from "@cloudflare/playwright"; interface Env { BROWSER: Fetcher; } export default { async fetch(request: Request, env: Env): Promise<Response> { const browser = await chromium.launch(env.BROWSER); const page = await browser.newPage(); await page.goto("https://example.com"); const screenshot = await page.screenshot(); await browser.close(); return new Response(screenshot, { headers: { "content-type": "image/png" } }); } }; ``` ### Key Differences from Puppeteer | Feature | Puppeteer | Playwright | |---------|-----------|------------| | **Import** | `import puppeteer from "@cloudflare/puppeteer"` | `import { chromium } from "@cloudflare/playwright"` | | **Launch** | `puppeteer.launch(env.MYBROWSER)` | `chromium.launch(env.BROWSER)` | | **Session API** | ✅ Advanced (sessions, history, limits) | ⚠️ Basic | | **Auto-waiting** | Manual `waitForSelector()` | Built-in auto-waiting | | **Selectors** | CSS only | CSS, text, XPath (via evaluate workaround) | **Recommendation**: Stick with Puppeteer unless you have existing Playwright tests to migrate. --- ## Session Management Browser sessions are managed using Durable Objects for state persistence across multiple requests. Sessions support hibernation, automatic cleanup, and concurrent connection handling. **Key Patterns**: - **Session Reuse** - Use `puppeteer.sessions()` and `puppeteer.connect()` to reuse browsers - **Browser Contexts** - Isolate cookies/cache while sharing browser instance - **Multiple Tabs** - Use tabs (`newPage()`) instead of multiple browsers for batch operations - **Disconnect vs Close** - Use `disconnect()` to keep session alive, `close()` to terminate **Load `references/session-management.md` for complete session lifecycle management, hibernation patterns, connection pooling strategies, and production examples.** --- ## Common Patterns **6 production-ready browser automation patterns**: 1. **Screenshot with KV Caching** - Cache screenshots for high-traffic URLs, reduce browser usage 2. **PDF Generation from HTML** - Convert custom HTML to PDF for invoices, reports,
Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.