/snapshot - Take a webpage snapshot
The /snapshot
endpoint captures both the HTML content and a screenshot of the webpage in one request. It returns the HTML as a text string and the screenshot as a Base64-encoded image.
- Go to
https://example.com/
. - Inject custom JavaScript.
- Capture the rendered HTML.
- Take a screenshot.
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/snapshot' \ -H 'Authorization: Bearer <apiToken>' \ -H 'Content-Type: application/json' \ -d '{ "url": "https://example.com/", "addScriptTag": [ { "content": "document.body.innerHTML = \"Snapshot Page\";" } ] }'
{ "success": true, "result": { "screenshot": "Base64EncodedScreenshotString", "content": "<html>...</html>" }}
import Cloudflare from "cloudflare";
const client = new Cloudflare({ apiToken: process.env["CLOUDFLARE_API_TOKEN"],});
const snapshot = await client.browserRendering.snapshot.create({ account_id: process.env["CLOUDFLARE_ACCOUNT_ID"], url: "https://example.com/", addScriptTag: [ { content: "document.body.innerHTML = \"Snapshot Page\";" } ]});
console.log(snapshot.content);
The html
property in the JSON payload, it sets the html to <html><body>Advanced Snapshot</body></html>
then does the following steps:
- Disable JavaScript.
- Sets the screenshot to
fullPage
. - Changes the page size
(viewport)
. - Waits up to
30000ms
or until theDOMContentLoaded
event fires. - Returns the rendered HTML content and a base-64 encoded screenshot of the page.
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/snapshot' \ -H 'Authorization: Bearer <apiToken>' \ -H 'Content-Type: application/json' \ -d '{ "html": "<html><body>Advanced Snapshot</body></html>", "setJavaScriptEnabled": false, "screenshotOptions": { "fullPage": true }, "viewport": { "width": 1200, "height": 800 }, "gotoOptions": { "waitUntil": "domcontentloaded", "timeout": 30000 } }'
{ "success": true, "result": { "screenshot": "AdvancedBase64Screenshot", "content": "<html><body>Advanced Snapshot</body></html>" }}
You can change the user agent at the page level by passing userAgent
as a top-level parameter in the JSON body. This is useful if the target website serves different content based on the user agent.
Many more options exist, like setting HTTP credentials using authenticate
, setting cookies
, and using gotoOptions
to control page load behaviour - check the endpoint reference for all available parameters.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-