You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 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
+
85
129
### Will Browser Rendering be detected by Bot Management?
86
130
87
131
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.
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,11 @@ Visit the [Browser Rendering API reference](/api/resources/browser_rendering/sub
90
90
91
91
### Capture a screenshot of an authenticated page
92
92
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:
94
98
95
99
```bash
96
100
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-
110
114
--output "authenticated-screenshot.png"
111
115
```
112
116
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
+
113
152
### Navigate and capture a full-page screenshot
114
153
115
154
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