Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
16d5d9e
Guardails docs
daisyfaithauma Feb 21, 2025
8e7de6b
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 21, 2025
1deed6d
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 24, 2025
b9b204a
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 24, 2025
912be66
Initial commit
daisyfaithauma Feb 24, 2025
9bc1e3d
quick actions endpoints
daisyfaithauma Feb 24, 2025
7a32d66
Fix
kodster28 Feb 24, 2025
33e5fa8
change to bullets
daisyfaithauma Feb 25, 2025
0e582ac
moved get started to a file
daisyfaithauma Feb 26, 2025
1ac96e4
summary
daisyfaithauma Feb 26, 2025
963a7f3
summar of endpoints
daisyfaithauma Feb 26, 2025
80549ce
fixed merge conflict
kodster28 Feb 26, 2025
423edaa
code samples
daisyfaithauma Feb 26, 2025
17c3b53
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
7f85bbc
code samples and title change
daisyfaithauma Feb 26, 2025
888f77b
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
13fbe0b
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 26, 2025
8a9346d
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 26, 2025
412e75e
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
08f7fe5
director listing
daisyfaithauma Feb 26, 2025
26957d9
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
1e91167
added code sample
daisyfaithauma Feb 26, 2025
864b0ee
index descriptions
daisyfaithauma Feb 26, 2025
7159abb
redirects
daisyfaithauma Feb 26, 2025
f01f28d
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 26, 2025
7602ec4
delete custom css
daisyfaithauma Feb 26, 2025
e162f5a
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
daa44b8
fixes from responses
daisyfaithauma Feb 26, 2025
17a6931
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
10d25f4
code fixes
daisyfaithauma Feb 26, 2025
105a878
parameters added
daisyfaithauma Feb 26, 2025
d17637a
Update get-started.mdx
kathayl Feb 26, 2025
7863d7c
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
b5bb84f
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
e90f198
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
43ba4b1
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
8afb47e
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
41a5fc8
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
b8655d5
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
93bff6e
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
581c2d3
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 27, 2025
3109164
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 27, 2025
8ee92dd
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
161492d
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
5335a26
minor fixes
daisyfaithauma Feb 27, 2025
e5fe663
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
3db0a71
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
048a6e2
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
5371bdf
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
d6b0ad7
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
0de2ee8
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
51803f9
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
69f7a8d
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
5adf461
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
9225637
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
21bb019
Update src/content/docs/browser-rendering/workers-binding-api/index.mdx
daisyfaithauma Feb 27, 2025
a4d75c9
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
b68d7e6
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
35e2abd
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
6fb4b3b
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
a80e9c8
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
ad050ce
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
11c235f
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
4653fd5
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
96fe9a2
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
e0d8002
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
048a8b1
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
d567aaf
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
eff3d93
minor fixes
daisyfaithauma Feb 27, 2025
e31c9ad
links fix
daisyfaithauma Feb 27, 2025
227b7b1
Update src/content/docs/browser-rendering/workers-binding-api/reuse-s…
daisyfaithauma Feb 27, 2025
ffd76d6
code fix
daisyfaithauma Feb 27, 2025
d4c37ca
removed link
daisyfaithauma Feb 27, 2025
bd711a5
Fix error
kodster28 Feb 27, 2025
0540b69
Added beta badge
kodster28 Feb 27, 2025
7034b6e
Update public/_redirects
kodster28 Feb 27, 2025
84accea
Small edit
kodster28 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/content/docs/ai-gateway/guardrails/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions src/content/docs/browser-rendering/get-started.mdx
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 0 additions & 12 deletions src/content/docs/browser-rendering/get-started/index.mdx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +26,8 @@ npm install @cloudflare/puppeteer --save-dev
3. Add your Browser Rendering binding to your new Wrangler configuration:

<WranglerConfig>
```toml

```toml title="wrangler.toml"
browser = { binding = "BROWSER" }
```
</WranglerConfig>
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/browser-rendering/platform/puppeteer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
@@ -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/<accountId>/browser-rendering/content' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <apiToken>' \
-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/<accountId>/browser-rendering/content' \
-H 'Authorization: Bearer <apiToken>' \
-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.
Original file line number Diff line number Diff line change
@@ -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";

<DirectoryListing />

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`
Original file line number Diff line number Diff line change
@@ -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/<accountId>/browser-rendering/pdf' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"addStyleTag": [
{ "content": "body { font-family: Arial; }" },
{ "url": "https://cdn.jsdelivr.net/npm/[email protected]/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/<accountId>/browser-rendering/pdf' \
-H 'Authorization: Bearer <apiToken>' \
-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/<acccountID>/browser-rendering/pdf \
-H 'Authorization: Bearer <apiToken>' \
-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.
Original file line number Diff line number Diff line change
@@ -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/<accountId>/browser-rendering/scrape' \
-H 'Authorization: Bearer <apiToken>' \
-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.
Loading
Loading