Browser Rendering


Enable your agents to scrape and extract web content in real-time. Cloudflare Browser Rendering provides headless browser automation capabilities that your agents can use to capture screenshots, extract HTML content, scrape specific elements, and gather structured data from any webpage.

Key Features

  • Puppeteer Integration: Full Puppeteer API support with Cloudflare's optimized fork
  • Session Management: Create, reuse, and manage browser sessions with keep-alive functionality
  • Content Extraction: Extract HTML, text, and structured data from web pages
  • Screenshot Capture: Take screenshots of web pages for visual analysis
  • PDF Generation: Convert web pages to PDF documents
  • Element Scraping: Target specific HTML elements for data extraction
  • Global Network: Browser instances run on Cloudflare's edge network worldwide
  • Rate Limiting: Built-in limits and monitoring for production usage

Getting Started

Wrangler Configuration

First, add browser rendering in your wrangler.json:

json

Agent Example

typescript

MCP Tool Integration

Integrate browser rendering capabilities with MCP tools:

typescript

TypeScript API Reference

You can access the browser rendering API via the env of the Agent or MCP Tool

typescript

Browser Instance Methods

this.browser.newPage(): Promise<Page>
Create a new page within the browser instance for web operations.

this.browser.isConnected(): boolean
Check if the browser session is still active and connected.

this.browser.close(): Promise<void>
Permanently close the browser instance and terminate all sessions.

this.browser.disconnect(): void
Disconnect from browser session while keeping it alive for reuse.

Page Methods

page.goto(url, options?): Promise<Response>
Navigate to a specific URL and wait for the page to load.

page.screenshot(options?): Promise<Buffer>
Capture a screenshot of the current page with customizable options.

page.setViewport(viewport): Promise<void>
Set the page viewport size for responsive testing.

page.evaluate(fn, ...args): Promise<any>
Execute JavaScript code within the page context.

page.waitForSelector(selector): Promise<ElementHandle>
Wait for an element to appear on the page.

page.close(): Promise<void>
Close the current page while keeping the browser session alive.

Browser Options

typescript

Examples

Learn how to integrate browser rendering capabilities into your agents and MCP tools through practical, real-world implementations.

Basic Puppeteer Usage

Get started with Cloudflare's Puppeteer integration using the standard Puppeteer API. For complete API documentation, see Cloudflare's Puppeteer Platform Guide.

typescript

Session Reuse Example

Optimize performance by reusing browser sessions with Durable Objects. This advanced pattern keeps browser instances alive for 60 seconds, reducing startup time and improving response times for multiple requests.

typescript

Best Practices

Essential patterns and techniques for building robust, performant browser automation workflows. These practices help you avoid common pitfalls and optimize resource usage.

Efficient Scraping

Use targeted CSS selectors and avoid scraping entire page content to minimize bandwidth and processing time.

typescript

Session Management

Implement browser session reuse patterns to reduce startup overhead and improve performance for multiple operations.

typescript

Error Handling & Retries

Implement robust error handling with exponential backoff and retry logic for network failures and rate limits.

typescript

Performance Optimization

Batch operations and use parallel processing to maximize throughput while respecting rate limits and resource constraints.

typescript

Limitations & Considerations

Important constraints and pricing considerations when using browser rendering at scale. Understanding these limits helps you design efficient workflows and manage costs effectively.

  • Rate Limits: 1000 requests per minute per account
  • Session Timeout: Browser sessions timeout after 5 minutes of inactivity
  • Memory Limits: Complex pages may exceed memory allocation
  • JavaScript Execution: Pages with heavy JavaScript may require longer wait times
  • Geographic Restrictions: Some websites may block requests from certain regions
  • Cost: Each browser operation incurs usage charges based on execution time
  • Memory Store - Maintain browser sessions across requests
  • Queues - Queue browser rendering tasks for batch processing
  • Storage - Store screenshots, PDFs, and scraped content
  • Memory Store - Cache frequently accessed web content

Official Documentation