SnapService logoSnapService
Documentation

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.

endpoints
GEThttps://preview.coders.lt/api/screenshot

Returns PNG image bytes. Serves from cache instantly, or triggers async capture and returns a placeholder with a Refresh header.

GEThttps://preview.coders.lt/api/raw

Returns 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.

ParameterTypeDescription
urlrequired
stringTarget URL (must start with https://)
width
numberViewport width (default: 480)
height
numberViewport 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.

320 × 568360 × 800375 × 667390 × 844414 × 896430 × 932480 × 2701280 × 7201366 × 7681440 × 9001536 × 8641920 × 1080

Response Behavior

The API uses standard HTTP status codes to communicate capture state.

200OK

Success

Returns the PNG image binary directly from cache on /api/screenshot. This is the fast path — no waiting.

302REDIRECT

Redirect

On /api/raw, cached images redirect to a stable static PNG URL. Use this for embed contexts that need a persistent image URL.

202PROCESSING

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.

Poll with HEAD requests until Refresh header is absent
response-headers

Polling Pattern

Check for the Refresh header on HEAD requests to know when the capture is ready.

202 Processing
HTTP/1.1 202 Accepted Content-Type: image/png Refresh: 5
200 Ready
HTTP/1.1 200 OK Content-Type: image/png (no Refresh header)

Simple usage

<img src="https://preview.coders.lt/api/screenshot?url=https://example.com" />
Try the live demo

JavaScript Implementation

captureWithPolling.js
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);
}