diff --git a/public/_redirects b/public/_redirects index 07b10d48849d635..2ab4f23fe407b20 100644 --- a/public/_redirects +++ b/public/_redirects @@ -179,6 +179,11 @@ /bots/reference/verified-bot-categories/ /bots/concepts/bot/verified-bots/categories/ 301 /bots/reference/verified-bot-policy/ /bots/concepts/bot/verified-bots/policy/ 301 +#browser-rendering +/browser-rendering/get-started/browser-rendering-with-do/ /browser-rendering/workers-binding-api/browser-rendering-with-do/ 301 +/browser-rendering/get-started/reuse-sessions/ /browser-rendering/workers-binding-api/reuse-sessions/ 301 +/browser-rendering/get-started/screenshots/ /browser-rendering/workers-binding-api/screenshots/ 301 + # byoip /byoip/about/dynamic-advertisement/ /byoip/concepts/dynamic-advertisement/ 301 /byoip/best-practices/dynamic-advertisement/ /byoip/concepts/dynamic-advertisement/best-practices/ 301 diff --git a/src/content/docs/ai-gateway/guardrails/index.mdx b/src/content/docs/ai-gateway/guardrails/index.mdx index 91db4c8678474a4..5a9e60a8950eac3 100644 --- a/src/content/docs/ai-gateway/guardrails/index.mdx +++ b/src/content/docs/ai-gateway/guardrails/index.mdx @@ -25,6 +25,7 @@ AI Gateway inspects all interactions in real time by evaluating content against AI Gateway proxies requests and responses, sitting between the user and the AI model. 2. Inspecting content: + - User prompts: AI Gateway checks prompts against safety parameters (for example, violence, hate, or sexual content). Based on your settings, prompts can be flagged or blocked before reaching the model. - Model responses: Once processed, the AI model response is inspected. If hazardous content is detected, it can be flagged or blocked before being delivered to the user. diff --git a/src/content/docs/browser-rendering/get-started.mdx b/src/content/docs/browser-rendering/get-started.mdx new file mode 100644 index 000000000000000..5abf934d66a51b3 --- /dev/null +++ b/src/content/docs/browser-rendering/get-started.mdx @@ -0,0 +1,11 @@ +--- +pcx_content_type: navigation +title: Get started +sidebar: + order: 2 +--- + +Browser rendering can be used in two ways: + +- [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts. +- [Quick Actions REST API](/browser-rendering/quick-actions-rest-api/) for simple actions. diff --git a/src/content/docs/browser-rendering/get-started/index.mdx b/src/content/docs/browser-rendering/get-started/index.mdx deleted file mode 100644 index d64864ac0a09c01..000000000000000 --- a/src/content/docs/browser-rendering/get-started/index.mdx +++ /dev/null @@ -1,12 +0,0 @@ ---- -pcx_content_type: navigation -title: Get started -sidebar: - order: 2 - group: - hideIndex: true ---- - -import { DirectoryListing } from "~/components"; - - diff --git a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx index 22a40c370f71631..fd78e0b7f04bb52 100644 --- a/src/content/docs/browser-rendering/how-to/pdf-generation.mdx +++ b/src/content/docs/browser-rendering/how-to/pdf-generation.mdx @@ -7,7 +7,7 @@ sidebar: import { Aside, WranglerConfig } from "~/components"; -As seen in the [Getting Started guide](/browser-rendering/get-started/screenshots/), Browser Rendering can be used to generate screenshots for any given URL. Alongside screenshots, you can also generate full PDF documents for a given webpage, and can also provide the webpage markup and style ourselves. +As seen in the [Getting Started guide](/browser-rendering/workers-binding-api/screenshots/), Browser Rendering can be used to generate screenshots for any given URL. Alongside screenshots, you can also generate full PDF documents for a given webpage, and can also provide the webpage markup and style ourselves. ## Prerequisites @@ -26,7 +26,8 @@ npm install @cloudflare/puppeteer --save-dev 3. Add your Browser Rendering binding to your new Wrangler configuration: -```toml + +```toml title="wrangler.toml" browser = { binding = "BROWSER" } ``` diff --git a/src/content/docs/browser-rendering/platform/puppeteer.mdx b/src/content/docs/browser-rendering/platform/puppeteer.mdx index 6e8b6717cb00319..76a21ed5057e6a4 100644 --- a/src/content/docs/browser-rendering/platform/puppeteer.mdx +++ b/src/content/docs/browser-rendering/platform/puppeteer.mdx @@ -11,7 +11,7 @@ import { TabItem, Tabs } from "~/components"; Puppeteer typically connects to a local Chrome or Chromium browser using the DevTools port. Refer to the [Puppeteer API documentation on the `Puppeteer.connect()` method](https://pptr.dev/api/puppeteer.puppeteer.connect) for more information. -The Workers team forked a version of Puppeteer and patched it to connect to the Workers Browser Rendering API instead. The [changes between Workers Puppeteer fork and the Puppeteer core](https://github.com/cloudflare/puppeteer/blob/main/src/puppeteer-core.ts) are minimal. After connecting, the developers can then use the full [Puppeteer API](https://github.com/cloudflare/puppeteer/blob/main/docs/api/index.md) as they would on a standard setup. +The Workers team forked a version of Puppeteer and patched it to connect to the Workers Browser Rendering API instead. After connecting, the developers can then use the full [Puppeteer API](https://github.com/cloudflare/puppeteer/blob/main/docs/api/index.md) as they would on a standard setup. Our version is open sourced and can be found in [Cloudflare's fork of Puppeteer](https://github.com/cloudflare/puppeteer). The npm can be installed from [npmjs](https://www.npmjs.com/) as [@cloudflare/puppeteer](https://www.npmjs.com/package/@cloudflare/puppeteer): @@ -67,7 +67,7 @@ This script [launches](https://pptr.dev/api/puppeteer.puppeteernode.launch) the ### Keep Alive -If users omit the `browser.close()` statement, it will stay open, ready to be connected to again and [re-used](/browser-rendering/get-started/reuse-sessions/) but it will, by default, close automatically after 1 minute of inactivity. Users can optionally extend this idle time up to 10 minutes, by using the `keep_alive` option, set in milliseconds: +If users omit the `browser.close()` statement, it will stay open, ready to be connected to again and [re-used](/browser-rendering/workers-binding-api/reuse-sessions/) but it will, by default, close automatically after 1 minute of inactivity. Users can optionally extend this idle time up to 10 minutes, by using the `keep_alive` option, set in milliseconds: ```js const browser = await puppeteer.launch(env.MYBROWSER, { keep_alive: 600000 }); diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx new file mode 100644 index 000000000000000..d4bb17611e512b8 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/content-endpoint.mdx @@ -0,0 +1,41 @@ +--- +pcx_content_type: how-to +title: Fetch HTML +sidebar: + order: 2 +--- + +The `/content` endpoint instructs the browser to navigate to a website and capture the fully rendered HTML of a page, including the `head` section, after JavaScript execution. This is ideal for capturing content from JavaScript-heavy or interactive websites. + +## Basic usage + +Go to `https://example.com` and return the rendered HTML. + +```bash +curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer ' \ + -d '{"url": "https://example.com"}' +``` + +## Advanced usage + +Navigate to `https://cloudflare.com/` but block images and stylesheets from loading. Undesired requests can be blocked by resource type (`rejectResourceTypes`) or by using a regex pattern (`rejectRequestPattern`). + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/content' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://cloudflare.com/", + "rejectResourceTypes": ["image"], + "rejectRequestPattern": ["/^.*\\.(css)"] +} + +``` + +### Parameters + +- `url` _(string)_ - The URL of the webpage to extract content from. +- `rejectResourceTypes` _(array)_ - Blocks specific resource types such as images, fonts from loading to improve performance. +- `rejectRequestPattern` _(array of regex patterns)_ - Prevents loading of resources matching specified patterns such as CSS files. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx new file mode 100644 index 000000000000000..fb9435a6bfb51b0 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/index.mdx @@ -0,0 +1,23 @@ +--- +pcx_content_type: navigation +title: Quick Actions REST API +sidebar: + order: 2 + group: + badge: Beta +--- + +The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. +The following are the available options: + +import { DirectoryListing } from "~/components"; + + + +Use the Quick Actions API when you need a fast, simple way to perform common browser tasks such as capturing screenshots, extracting HTML, or generating PDFs without writing complex scripts. If you require more advanced automation, custom workflows, or persistent browser sessions, the [Workers Binding API](/browser-rendering/workers-binding-api/) is the better choice. + +## Before you begin + +Before you begin, make sure you [create a custom API Token](/fundamentals/api/get-started/create-token/) with the following permissions: + +- `Browser Rendering - Edit` diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx new file mode 100644 index 000000000000000..7ca1c02a0a15438 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/pdf-endpoint.mdx @@ -0,0 +1,86 @@ +--- +pcx_content_type: how-to +title: Render PDF +sidebar: + order: 5 +--- + +The `/pdf` endpoint instructs the browser to render the webpage as a PDF document. + +## Basic usage + +Navigate to `https://example.com/` and inject custom CSS and an external stylesheet. Then return the rendered page as a PDF. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addStyleTag": [ + { "content": "body { font-family: Arial; }" }, + { "url": "https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" } + ] + }' \ + --output "output.pdf" +``` + +## Advanced usage + +Navigate to `https://example.com`, first setting an additional HTTP request header and configuring the page size (`viewport`). Then, wait until there are no more than 2 network connections for at least 500 ms, or until the maximum timeout of 4500 ms is reached, before considering the page loaded and returning the rendered PDF document. + +The `goToOptions` parameter exposes most of [Puppeteer'd API](https://pptr.dev/api/puppeteer.gotooptions). + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "setExtraHTTPHeaders": { + "X-Custom-Header": "value" + }, + "viewport": { + "width": 1200, + "height": 800 + }, + "gotoOptions": { + "waitUntil": "networkidle2", + "timeout": 45000 + } + }' \ + --output "advanced-output.pdf" +``` + +## PDF with no images or CSS + +Use PDF with no images or CSS if you want to accelerate the scanning process and you do not need the images. + +```bash +curl -X POST https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://cloudflare.com/", + "rejectResourceTypes": ["image"], + "rejectRequestPattern": ["/^.*\\.(css)"] +}' \ + --output "cloudflare.pdf" +``` + +## Parameters + +- `url` _(string)_ - The webpage URL to render as a PDF. +- `addStyleTag` _(array of objects)_ - Injects custom CSS before generating the PDF. + - `content` _(string)_ - Inline CSS styles. + - `url` _(string)_ - URL of an external stylesheet. +- `setExtraHTTPHeaders` _(object)_ - Adds custom HTTP headers when making the request. + - `X-Custom-Header` _(string)_ - Example of a custom header. +- `viewport` _(object)_ - Defines the browser viewport size. + - `width` _(number)_ - Viewport width in pixels. + - `height` _(number)_ - Viewport height in pixels. +- `gotoOptions` _(object)_ - Configures page navigation settings. + - `waitUntil` _(string)_ - Defines when the browser considers the page fully loaded. + - `timeout` _(number)_ - Maximum wait time before failing the request. +- `rejectResourceTypes` _(array)_ - Blocks specific resource types to improve rendering performance. +- `rejectRequestPattern` _(array of regex patterns)_ - Prevents loading of resources matching certain patterns. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx new file mode 100644 index 000000000000000..95d79405c0a305d --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/scrape-endpoint.mdx @@ -0,0 +1,81 @@ +--- +pcx_content_type: how-to +title: Scrape HTML elements +sidebar: + order: 7 +--- + +The `/scrape` endpoint extracts structured data from specific elements on a webpage, returning details such as element dimensions and inner HTML. + +## Basic usage + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/scrape' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "elements": [{ + "selector": "h1" + }, + { + "selector": "a" + }] +} +``` + +### JSON response + +```json title="json response" +{ + "success": true, + "result": [ + { + "results": [ + { + "attributes": [], + "height": 39, + "html": "Example Domain", + "left": 100, + "text": "Example Domain", + "top": 133.4375, + "width": 600 + } + ], + "selector": "h1" + }, + { + "results": [ + { + "attributes": [ + { "name": "href", "value": "https://www.iana.org/domains/example" } + ], + "height": 20, + "html": "More information...", + "left": 100, + "text": "More information...", + "top": 249.875, + "width": 142 + } + ], + "selector": "a" + } + ] +} +``` + +## Parameters + +- `url` _(string)_ - The webpage to extract data from. +- `elements` _(object)_ - Defines the elements to extract from the page. + - `selectors` _(array of strings)_ - List of CSS selectors identifying elements to scrape (e.g., `"h1"`, `".article"`). + +### Response fields + +- `results` _(array of objects)_ - Contains extracted data for each selector. + - `selector` _(string)_ - The CSS selector used. + - `results` _(array of objects)_ - List of extracted elements matching the selector. + - `text` _(string)_ - Inner text of the element. + - `html` _(string)_ - Inner HTML of the element. + - `attributes` _(array of objects)_ - List of extracted attributes such as `href` for links. + - `height`, `width`, `top`, `left` _(number)_ - Position and dimensions of the element. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx new file mode 100644 index 000000000000000..63d665dc7f1adc9 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/screenshot-endpoint.mdx @@ -0,0 +1,95 @@ +--- +pcx_content_type: how-to +title: Capture screenshot +sidebar: + order: 3 +--- + +The `/screenshot` endpoint renders the webpage by processing its HTML and JavaScript, then captures a screenshot of the fully rendered page. + +## Basic usage + +Sets the HTML content of the page to `Hello World!` and then takes a screenshot. The option `omitBackground` hides the default white background and allows capturing screenshots with transparency. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "html": "Hello World!", + "screenshotOptions": { + "omitBackground": true + } + }' \ + --output "screenshot.webp" +``` + +## Advanced usage + +Navigate to `https://cloudflare.com/`, changing the page size and waiting until there are no active network connections or up to a maximum of `4500ms`. Then take a `fullPage` screenshot. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://cloudflare.com/", + "screenshotOptions": { + "fullPage": true, + "omitBackground": true, + }, + "viewport": { + "width": 1280, + "height": 720 + }, + "gotoOptions": { + "waitUntil": "networkidle0", + "timeout": 45000 + } + }' \ + --output "advanced-screenshot.webp" +``` + +## Customize CSS and embed custom JavaScript + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/screenshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + + { "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" } + ], + "addStyleTag": [ + { + "content": "div { background: linear-gradient(45deg, #2980b9 , #82e0aa ); }" + }, + { + "url": "https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" + } + ] + }' \ + --output "screenshot.webp" +``` + +## Parameters + +- `url` _(string)_ - The webpage URL to take a screenshot of. +- `html` _(string)_ - Instead of a URL, allows rendering custom HTML for the screenshot. +- `screenshotOptions` _(object)_ - Configures the screenshot format and quality. + - `omitBackground` _(boolean)_ - Removes the default white background when taking a screenshot. +- `viewport` _(object)_ - Sets the browser viewport dimensions for rendering. + - `width` _(number)_ - Viewport width in pixels. + - `height` _(number)_ - Viewport height in pixels. +- `gotoOptions` _(object)_ - Configures how and when the page is considered fully loaded. + - `waitUntil` _(string)_ - Defines when the browser considers navigation complete (`networkidle0`, `domcontentloaded`). + - `networkidle0` - Waits until there are no more than 0 network connections for at least 500 ms before taking a screenshot. + - `timeout` _(number)_ - Maximum wait time (in milliseconds) before navigation times out. +- `addScriptTag` _(array of objects)_ - Injects JavaScript code before taking a screenshot. + - `url` _(string)_ - Loads an external script file before rendering. + - `content` _(string)_ - Runs inline JavaScript before rendering. +- `addStyleTag` _(array of objects)_ - Injects CSS styles before rendering. + - `content` _(string)_ - Defines inline CSS rules. + - `url` _(string)_ - Loads external stylesheets before rendering. diff --git a/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx new file mode 100644 index 000000000000000..8bbb4263e3a2d58 --- /dev/null +++ b/src/content/docs/browser-rendering/quick-actions-rest-api/snapshot.mdx @@ -0,0 +1,98 @@ +--- +pcx_content_type: how-to +title: Take a webpage snapshot +sidebar: + order: 6 +--- + +The `/snapshot` endpoint captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image. + +## Basic usage + +1. Go to `https://example.com/`. +2. Inject custom JavaScript. +3. Capture the rendered HTML. +4. Take a screenshot. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com/", + "addScriptTag": [ + { "content": "document.body.innerHTML = \"Snapshot Page\";" } + ] + }' +``` + +### JSON response + +```json title="json response" +{ + "status": true, + "result": { + "screenshot": "Base64EncodedScreenshotString", + "content": "..." + } +} +``` + +## Advanced usage + +The `html` property in the JSON payload, it sets the html to `Advanced Snapshot` then does the following steps: + +1. Disable JavaScript. +2. Changes the page size `(viewport)`. +3. Waits up to `30000ms` or until the `DOMContentLoaded` event starts. +4. Returns the rendered HTML content and a base-64 encoded screenshot of the page. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/snapshot' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "html": "Advanced Snapshot", + "setJavaScriptEnabled": false, + "viewport": { + "width": 1200, + "height": 800 + }, + "gotoOptions": { + "waitUntil": "domcontentloaded", + "timeout": 30000 + } + }' +``` + +### JSON response + +```json title="json response" +{ + "status": true, + "errors": [], + "result": { + "screenshot": "AdvancedBase64Screenshot", + "content": "Advanced Snapshot" + } +} +``` + +## Parameters + +- `url` _(string)_ - The URL of the page to snapshot. +- `html` _(string)_ - Allows passing custom HTML instead of a URL. +- `setJavaScriptEnabled` _(boolean)_ - Enables or disables JavaScript execution on the page. +- `viewport` \*(object)- Sets the rendering viewport dimensions. + - `width` _(number)_ - Width in pixels. + - `height` _(number)_ - Height in pixels. +- `gotoOptions` _(object)_ - Determines when the page is fully loaded. + - `waitUntil` _(string)_ - Defines the loading strategy (`domcontentloaded`, `networkidle2`). + - `timeout` _(number)_ - Timeout duration in milliseconds. +- `allowResourceTypes` _(array of strings)_ - Restricts the types of resources allowed to load. + - Example: [`document`, `script`] - Only allows HTML documents and scripts to load, preventing images, stylesheets, and other resources. + +### Response fields + +- `screenshot` _(string)_ - Base64-encoded image of the rendered page. +- `content` _(string)_ - Fully rendered HTML of the page. diff --git a/src/content/docs/browser-rendering/get-started/browser-rendering-with-DO.mdx b/src/content/docs/browser-rendering/workers-binding-api/browser-rendering-with-DO.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/browser-rendering-with-DO.mdx rename to src/content/docs/browser-rendering/workers-binding-api/browser-rendering-with-DO.mdx diff --git a/src/content/docs/browser-rendering/workers-binding-api/index.mdx b/src/content/docs/browser-rendering/workers-binding-api/index.mdx new file mode 100644 index 000000000000000..dbfac2ebb499ad5 --- /dev/null +++ b/src/content/docs/browser-rendering/workers-binding-api/index.mdx @@ -0,0 +1,14 @@ +--- +pcx_content_type: navigation +title: Workers Binding API +sidebar: + order: 2 +--- + +import { DirectoryListing } from "~/components"; + +The Workers Binding API allows you to execute advanced browser rendering scripts within Cloudflare Workers. It provides developers the flexibility to automate and control complex workflows and browser interactions. The following options are available for browser rendering tasks: + + + +Use the Workers Binding API when you need advanced browser automation, custom workflows, or complex interactions beyond basic rendering. For quick, one-off tasks like capturing screenshots or extracting HTML, the [Quick Actions REST API](/browser-rendering/quick-actions-rest-api/) is the simpler choice. diff --git a/src/content/docs/browser-rendering/get-started/reuse-sessions.mdx b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx similarity index 93% rename from src/content/docs/browser-rendering/get-started/reuse-sessions.mdx rename to src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx index 9c1f54f8d5ec77c..97a19866dacea06 100644 --- a/src/content/docs/browser-rendering/get-started/reuse-sessions.mdx +++ b/src/content/docs/browser-rendering/workers-binding-api/reuse-sessions.mdx @@ -7,7 +7,7 @@ sidebar: import { Render, PackageManagers, WranglerConfig } from "~/components"; -The best way to improve the performance of your browser rendering worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/get-started/browser-rendering-with-do/), which allows you to keep a long running connection from a worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. +The best way to improve the performance of your browser rendering Worker is to reuse sessions. One way to do that is via [Durable Objects](/browser-rendering/workers-binding-api/browser-rendering-with-do/), which allows you to keep a long running connection from a Worker to a browser. Another way is to keep the browser open after you've finished with it, and connect to that session each time you have a new request. In short, this entails using `browser.disconnect()` instead of `browser.close()`, and, if there are available sessions, using `puppeteer.connect(env.MY_BROWSER, sessionID)` instead of launching a new browser session. @@ -51,6 +51,7 @@ compatibility_date = "2023-03-14" compatibility_flags = [ "nodejs_compat" ] browser = { binding = "MYBROWSER" } + ``` diff --git a/src/content/docs/browser-rendering/get-started/screenshots.mdx b/src/content/docs/browser-rendering/workers-binding-api/screenshots.mdx similarity index 100% rename from src/content/docs/browser-rendering/get-started/screenshots.mdx rename to src/content/docs/browser-rendering/workers-binding-api/screenshots.mdx