API Reference
SnapService
Integrate pixel-perfect screenshots into your app with a single GET request. Domain-level caching, async processing, and intelligent polling built in.
Endpoints
All endpoints accept GET requests and are publicly accessible.
https://preview.coders.lt/api/screenshotReturns PNG image bytes. Serves from cache instantly, or triggers async capture and returns a placeholder with a Refresh header.
https://preview.coders.lt/api/rawReturns HTTP 302 redirect to the static cached image path. Useful when you need a stable CDN-style URL.
Query Parameters
All parameters are passed as URL query strings.
| Parameter | Type | Description |
|---|---|---|
urlrequired | string | Target URL (must start with https://) |
width | number | Viewport width (default: 480) |
height | number | Viewport height (default: 270) |
Allowed Resolutions
Only specific viewport resolutions are supported for security and performance. If one dimension is provided, the other is inferred. Defaults to 480×270 when no match is found.
Response Behavior
The API uses standard HTTP status codes to communicate capture state.
Success
Returns the PNG image binary directly from cache on /api/screenshot. This is the fast path — no waiting.
Redirect
On /api/raw, cached images redirect to a stable static PNG URL. Use this for embed contexts that need a persistent image URL.
Accepted — generating in background
The capture is queued. A placeholder image is returned immediately with a Refresh: 5 header. Poll using HEAD requests until the header disappears.
Refresh header is absentPolling Pattern
Check for the Refresh header on HEAD requests to know when the capture is ready.
Simple usage
<img src="https://preview.coders.lt/api/screenshot?url=https://example.com" />JavaScript Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/**
* Fetches a screenshot and handles async processing
* by respecting the 'Refresh' header.
*
* @param {string} url - The URL to capture
* @param {HTMLImageElement} imgElement - Image element to update
*/
async function captureWithPolling(url, imgElement) {
const apiEndpoint = `https://preview.coders.lt/api/screenshot?url=${encodeURIComponent(url)}`;
// Initial request — triggers capture or returns cached image
imgElement.src = apiEndpoint;
const poll = async () => {
try {
const response = await fetch(apiEndpoint, { method: 'HEAD' });
const refreshHeader = response.headers.get('Refresh');
if (refreshHeader) {
// Still processing — retry after the suggested delay
setTimeout(poll, parseInt(refreshHeader) * 1000);
} else {
// Ready — reload the image
imgElement.src = apiEndpoint;
}
} catch (err) {
console.error("Polling failed:", err);
}
};
setTimeout(poll, 2000);
}