Skip to content

Commit ee2419f

Browse files
committed
[Browser Rendering] Add how to take a screenshot of a specific element using selector
1 parent 08f82c6 commit ee2419f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,22 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
9898
}' \
9999
--output "screenshot.png"
100100
```
101+
## Take a screenshot of a specific element using the selector option
102+
To capture a screenshot of a specific element on a webpage, use the `selector` option with a valid CSS selector. You can also configure the `viewport` to control the page dimensions during rendering.
103+
104+
```bash
105+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/screenshot' \
106+
-H 'Authorization: Bearer <apiToken>' \
107+
-H 'Content-Type: application/json' \
108+
-d '{
109+
"url": "https://example.com",
110+
"selector": "#example_element_name",
111+
"viewport": {
112+
"width": 1200,
113+
"height": 1600
114+
}
115+
}' \
116+
--output "screenshot.png"
117+
```
101118

102119
Many more options exist, like setting HTTP credentials using `authenticate`, setting `cookies`, and using `gotoOptions` to control page load behaviour - check the endpoint [reference](/api/resources/browser_rendering/subresources/screenshot/methods/create/) for all available parameters.

0 commit comments

Comments
 (0)