Skip to content

Commit f7a4985

Browse files
committed
Add REST API auth FAQ entry, expand screenshot auth examples, update examples page
1 parent 063ea1d commit f7a4985

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

src/content/docs/browser-rendering/examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Use these [REST API](/browser-rendering/rest-api/) examples to perform quick, co
2929
/>
3030
<LinkCard
3131
title="Take a screenshot of an authenticated page"
32-
description="Capture a screenshot of a webpage that requires login by providing session cookies."
32+
description="Capture a screenshot of a webpage that requires login using cookies, HTTP Basic Auth, or custom headers."
3333
href="/browser-rendering/rest-api/screenshot-endpoint/#capture-a-screenshot-of-an-authenticated-page"
3434
/>
3535
<LinkCard

src/content/docs/browser-rendering/faq.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,50 @@ Not yet. Local development currently has the following limitation(s):
8282

8383
<Render file="remote-binding-note" product="workers" />
8484

85+
### How do I render authenticated pages using the REST API?
86+
87+
If the page you are rendering requires authentication, you can pass credentials using one of the following methods. These parameters work with all [REST API](/browser-rendering/rest-api/) endpoints.
88+
89+
HTTP Basic Auth:
90+
91+
```json
92+
{
93+
"authenticate": {
94+
"username": "user",
95+
"password": "pass"
96+
}
97+
}
98+
```
99+
100+
Cookie-based authentication:
101+
102+
```json
103+
{
104+
"cookies": [
105+
{
106+
"name": "session_id",
107+
"value": "abc123",
108+
"domain": "example.com",
109+
"path": "/",
110+
"secure": true,
111+
"httpOnly": true
112+
}
113+
]
114+
}
115+
```
116+
117+
Token-based authentication:
118+
119+
```json
120+
{
121+
"setExtraHTTPHeaders": {
122+
"Authorization": "Bearer your-token"
123+
}
124+
}
125+
```
126+
127+
For complete worked examples of all three methods, refer to [Capture a screenshot of an authenticated page](/browser-rendering/rest-api/screenshot-endpoint/#capture-a-screenshot-of-an-authenticated-page).
128+
85129
### Will Browser Rendering be detected by Bot Management?
86130

87131
Yes, Browser Rendering requests are always identified as bot traffic by Cloudflare. Cloudflare does not enforce bot protection by default — that is the customer's choice.

src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ Visit the [Browser Rendering API reference](/api/resources/browser_rendering/sub
9090

9191
### Capture a screenshot of an authenticated page
9292

93-
Some webpages require authentication before you can view their content. To capture a screenshot of these pages, you must provide valid session cookies. The following example navigates to a page that requires login. By providing a valid cookie in the `cookies` array, Browser Rendering will be able to access the secure content in order to capture the screenshot.
93+
Some webpages require authentication before you can view their content. Browser Rendering supports three authentication methods, which work across all [REST API](/browser-rendering/rest-api/) endpoints. For a quick reference of all methods, refer to [How do I render authenticated pages using the REST API?](/browser-rendering/faq/#how-do-i-render-authenticated-pages-using-the-rest-api).
94+
95+
#### Cookie-based authentication
96+
97+
Provide valid session cookies to access pages that require login:
9498

9599
```bash
96100
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
@@ -110,6 +114,41 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
110114
--output "authenticated-screenshot.png"
111115
```
112116

117+
#### HTTP Basic Auth
118+
119+
Use the `authenticate` parameter for pages behind HTTP Basic Authentication:
120+
121+
```bash
122+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
123+
-H 'Authorization: Bearer <apiToken>' \
124+
-H 'Content-Type: application/json' \
125+
-d '{
126+
"url": "https://example.com/protected-page",
127+
"authenticate": {
128+
"username": "user",
129+
"password": "pass"
130+
}
131+
}' \
132+
--output "authenticated-screenshot.png"
133+
```
134+
135+
#### Token-based authentication
136+
137+
Add custom authorization headers using `setExtraHTTPHeaders`:
138+
139+
```bash
140+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
141+
-H 'Authorization: Bearer <apiToken>' \
142+
-H 'Content-Type: application/json' \
143+
-d '{
144+
"url": "https://example.com/protected-page",
145+
"setExtraHTTPHeaders": {
146+
"Authorization": "Bearer your-token"
147+
}
148+
}' \
149+
--output "authenticated-screenshot.png"
150+
```
151+
113152
### Navigate and capture a full-page screenshot
114153

115154
Navigate to `https://cloudflare.com/`, change the page size (`viewport`) and wait until there are no active network connections (`waitUntil`) or up to a maximum of `4500ms` (`timeout`) before capturing a `fullPage` screenshot.

0 commit comments

Comments
 (0)