Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 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
@@ -0,0 +1,39 @@
---
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

Navigate 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

```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,17 @@
---
pcx_content_type: navigation
title: Quick Actions REST API
sidebar:
order: 2
---

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 like 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, make sure to [create a custom **API Token**](/fundamentals/api/get-started/create-token/) with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
pcx_content_type: how-to
title: PDF API
sidebar:
order: 5
---

The `/pdf` endpoint instructs the browser to render the webpage as a PDF document.

## Basic usage

```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; }" }
]
}' \
--output "output.pdf"
```

## Advanced usage

```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

This is ideal when the user wants to so speed up the scanning process and does 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
pcx_content_type: how-to
title: Screenshot API
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

```bash
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"html": "Hello World!",
"screenshotOptions": {
"type": "webp",
"omitBackground": true
}
}' \
--output "screenshot.webp"
```

## Advanced usage

```bash
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://cloudflare.com/",
"screenshotOptions": {
"omitBackground": true,
},
"viewport": {
"width": 1280,
"height": 720
},
"gotoOptions": {
"waitUntil": "networkidle0",
"timeout": 45000
}
}' \
--output "advanced-screenshot.webp"
```

## Customise CSS

```bash
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"addScriptTag": [
{ "url": "https://code.jquery.com/jquery-3.7.1.min.js" },
{ "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" }
],
"addStyleTag": [
{
"content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }"
},
{
"url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css"
}
]
}' \
--output "screenshot.webp"
```

## Parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. It should be in the api docs and some of these are common to all endpoints.


- `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 500ms 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.
Loading
Loading