Skip to content

Commit 9bc1e3d

Browse files
quick actions endpoints
1 parent 912be66 commit 9bc1e3d

File tree

9 files changed

+127
-8
lines changed

9 files changed

+127
-8
lines changed

src/content/docs/browser-rendering/get-started/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pcx_content_type: navigation
33
title: Get started
44
sidebar:
55
order: 2
6-
group:
7-
hideIndex: true
86
---
97

108
import { DirectoryListing } from "~/components";
119

10+
Browser rendering can be used in two ways: the [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts and the Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/).
11+
1212
<DirectoryListing />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Retrieve HTML content
4+
sidebar:
5+
order: 2
6+
---
7+
8+
Retrieve the HTML content of a specified URL by sending a POST request to the `/content` endpoint.
9+
10+
```
11+
curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/content' \
12+
-H 'Content-Type: application/json' \
13+
-H 'Authorization: Bearer <apiToken>' \
14+
-d '{"url": "https://example.com"}'
15+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Customize CSS and take a screenshot
4+
sidebar:
5+
order: 4
6+
---
7+
8+
Customise the rendering by adding external JavaScript and CSS before capturing a screenshot.
9+
10+
```
11+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/screenshot' \
12+
-H 'Authorization: Bearer <apiToken>' \
13+
-H 'Content-Type: application/json' \
14+
-d '{
15+
"url": "https://example.com/",
16+
"addScriptTag": [
17+
{ "url": "https://code.jquery.com/jquery-3.7.1.min.js" },
18+
{ "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" }
19+
],
20+
"addStyleTag": [
21+
{
22+
"content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }"
23+
},
24+
{
25+
"url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css"
26+
}
27+
]
28+
}' \
29+
--output "screenshot.webp"
30+
```
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
---
22
pcx_content_type: navigation
3-
title: Workers Binding API
3+
title: Quick Actions API
44
sidebar:
55
order: 2
6-
group:
7-
hideIndex: true
86
---
97

10-
import { DirectoryListing } from "~/components";
8+
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. This API is designed to help you interact with web pages quickly and efficiently.
119

12-
<DirectoryListing />
10+
Before you begin, make sure to create a custom **API Token** with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Generate PDF
4+
sidebar:
5+
order: 5
6+
---
7+
8+
```
9+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/pdf' \
10+
-H 'Authorization: Bearer <apiToken>' \
11+
-H 'Content-Type: application/json' \
12+
-d '{
13+
"url": "https://example.com/",
14+
"addStyleTag": [
15+
{ "content": "body { font-family: Arial; }" }
16+
]
17+
}' \
18+
--output "output.pdf"
19+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Scrape content
4+
sidebar:
5+
order: 7
6+
---
7+
8+
```
9+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/scrape' \
10+
-H 'Authorization: Bearer <apiToken>' \
11+
-H 'Content-Type: application/json' \
12+
-d '{
13+
"url": "https://example.com/",
14+
"scrapeOptions": {
15+
"selectors": ["h1", ".article"]
16+
}
17+
}'
18+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Render HTML and capture screenshot
4+
sidebar:
5+
order: 3
6+
---
7+
8+
Render a provided HTML string and capture a screenshot with specific options.
9+
10+
```
11+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/screenshot' \
12+
-H 'Authorization: Bearer <apiToken>' \
13+
-H 'Content-Type: application/json' \
14+
-d '{
15+
"html": "Hello World!",
16+
"screenshotOptions": {
17+
"type": "webp",
18+
"omitBackground": true
19+
}
20+
}' \
21+
--output "screenshot.webp"
22+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Capture snapshot
4+
sidebar:
5+
order: 6
6+
---
7+
8+
```
9+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/snapshot' \
10+
-H 'Authorization: Bearer <apiToken>' \
11+
-H 'Content-Type: application/json' \
12+
-d '{
13+
"url": "https://example.com/",
14+
"addScriptTag": [
15+
{ "content": "document.title = \"Snapshot Page\";" }
16+
]
17+
}'
18+
```

src/content/docs/browser-rendering/workers-binding-api/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ title: Workers Binding API
44
sidebar:
55
order: 2
66
group:
7-
hideIndex: true
87
---
98

109
import { DirectoryListing } from "~/components";

0 commit comments

Comments
 (0)