cloudflare-browser-rendering
Add headless Chrome automation with Puppeteer/Playwright on Cloudflare Workers. Use when: taking screenshots, generating PDFs, web scraping, crawling sites, browser automation, or troubleshooting XPath errors, browser timeouts, binding not passed errors, or session limits.
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-23 **Dependencies**: cloudflare-worker-base (for Worker setup) **Latest Versions**: @cloudflare/[email protected] (July 2025), @cloudflare/[email protected] (Playwright v1.55 GA Sept 2025), [email protected] **Recent Updates (2025)**: - **Sept 2025**: Playwright v1.55 GA, Stagehand framework support (Workers AI), /links excludeExternalLinks param - **Aug 2025**: Billing GA (Aug 20), /sessions endpoint in local dev, X-Browser-Ms-Used header - **July 2025**: Playwright v1.54.1 + MCP v0.0.30, Playwright local dev support ([email protected]+), Puppeteer v22.13.1 sync, /content returns title, /json custom_ai param, /screenshot viewport 1920x1080 default - **June 2025**: Web Bot Auth headers auto-included - **April 2025**: Playwright support launched, free tier introduced --- ## 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 npm install @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 npx 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 --- ## 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 APIs** (complete reference: https://pptr.dev/api/): **Global Functions:** - `puppeteer.launch(env.MYBROWSER, options?)` - Launch new browser (CRITICAL: must pass binding) - `puppeteer.connect(env.MYBROWSER, sessionId)` - Connect to existing session - `puppeteer.sessions(env.MYBROWSER)` - List running sessions - `puppeteer.history(env.MYBROWSER)` - List recent sessions (open + closed) - `puppeteer.limits(env.MYBROWSER)` - Check account limits **Browser Methods:** - `browser.newPage()` - Create new tab (preferred over launching new browsers) - `browser.sessionId()` - Get session ID for reuse - `browser.close()` - Terminate session - `browser.disconnect()` - Keep session alive for reuse - `browser.createBrowserContext()` - Isolated incognito context (separate cookies/cache) **Page Methods:** - `page.goto(url, { waitUntil, timeout })` - Navigate (use `"networkidle0"` for dynamic content) - `page.screenshot({ fullPage, type, quality, clip })` - Capture image - `page.pdf({ format, printBackground, margin })` - Generate PDF - `page.evaluate(() => ...)` - Execute JS in browser (data extraction, XPath workaround) - `page.content()` / `page.setContent(html)` - Get/set HTML - `page.waitForSelector(selector)` - Wait for element - `page.type(selector, text)` / `page.click(selector)` - Form interaction **Critical Patterns:** ```typescript // Must pass binding const browser = await puppeteer.launch(env.MYBROWSER); // ✅ // const browser = await puppeteer.launch(); // ❌ Error! // Session reuse for performance const sessions = await puppeteer.sessions(env.MYBROWSER); const freeSessions = sessions.filter(s => !s.connectionId); if (freeSessions.length > 0) { browser = await puppeteer.connect(env.MYBROWSER, freeSessions[0].sessionId); } // Keep session alive await browser.disconnect(); // Don't close // XPath workaround (not directly supported) const data = await page.evaluate(() => { return new XPathEvaluator() .createExpression("/html/body/div/h1") .evaluate(document, XPathResult.FIRST_ORDERED_NODE_TYPE) .singleNodeValue.innerHTML; }); ``` --- ## Playwright API Reference **Status**: GA (Sept 2025) - Playwright v1.55, MCP v0.0.30 support, local dev support ([email protected]+) **Installation:** ```bash npm install @cloudflare/playwright ``` **Configuration Requirements (2025 Update):** ```jsonc { "compatibility_flags": ["nodejs_compat"], "compatibility_date": "2025-09-15" // Required for Playwright v1.55 } ``` **Basic Usage:** ```typescript import { chromium } from "@cloudflare/playwright"; 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(); ``` **Puppeteer vs Playwright:** - **Import**: `puppeteer` vs `{ chromium }` from "@cloudflare/playwright" - **Session API**: Puppeteer has advanced session management (sessions/history/limits), Playwright basic - **Auto-waiting**: Playwright has built-in auto-waiting, Puppeteer requires manual `waitForSelector()` - **MCP Support**: Playwright MCP v0.0.30 (July 2025), Playwright MCP server available **Recommendation**: Use Puppeteer for session reuse patterns. Use Playwright if migrating existing tests or need MCP integration. **Official Docs**: https://developers.cloudflare.com/browser-rendering/playwright/ --- ## Session Management **Why**: Launching new browsers is slow and consumes concurrency limits. Reuse sessions for faster response, lower concurrency usage, better resource utilization. ### Sessi
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.