Capture and preview with fetch
Send the URL and capture options to the screenshot endpoint, read the response with res.blob(), then create a temporary preview URL with URL.createObjectURL.
const params = new URLSearchParams({
url: "https://example.com",
full_page: "true",
});
const res = await fetch(`https://api.snapshotflow.com/screenshot?${params}`, {
headers: { "X-Api-Key": YOUR_API_KEY },
});
if (!res.ok) throw new Error(`Capture failed: ${res.status}`);
const blob = await res.blob();
document.querySelector("#preview").src = URL.createObjectURL(blob);
Browser response options
- Binary images: receive PNG, JPEG, or WebP bytes and display them through a blob URL.
- JSON responses: request base64 data or a hosted URL when raw bytes do not fit the workflow.
- Legacy applications: use
XMLHttpRequestwithresponseType = "blob". - Multiple pages: send a POST request to
/batchfor grouped captures.
Keep production keys on the server
Do not embed X-Api-Key values in customer-facing JavaScript. Route production requests through a backend proxy that reads the key from an environment variable, calls SnapshotFlow, and streams the response to the browser.
Read the browser JavaScript guide
The guide includes complete fetch and XMLHttpRequest examples, blob cleanup, response formats, and the backend proxy pattern. New accounts include 300 screenshots for the lifetime of the account.