Rendering

Render a URL or HTML (query form)

Every option as a query parameter, so a render can sit in an <img src>. Accepts a bearer key or a signed URL (keyId + sig).

get/api/render

Request

  • Base URL: https://snaplab.dev
  • URL: https://snaplab.dev/api/render
  • Auth: one of:
    • HTTP bearer
    • API key in query parameter keyId and API key in query parameter sig

Query parameters

urlstring

Absolute http(s) URL. Provide this or html/template.

htmlstring

URL-encoded HTML to render instead of navigating.

templatestring

URL-encoded {{ template }} HTML.

datastring

JSON object (URL-encoded) with values for the template.

cssstring

URL-encoded stylesheet injected into <head>.

googleFontsstring

Comma-separated font families.

format'png' | 'jpeg' | 'webp' | 'avif' | 'pdf'

Output format.

viewport'desktop' | 'laptop' | 'tablet' | 'mobile' | 'wide'

Viewport preset.

widthinteger

Viewport width in CSS pixels.

heightinteger

Viewport height in CSS pixels.

deviceScaleFactornumber

Pixel ratio (0.5–3).

mobile'true' | 'false' | '1' | '0'

Sugar for viewport=mobile.

fullPage'true' | 'false' | '1' | '0'

Capture the whole scrollable page.

selectorstring

Capture just this element.

qualityinteger

1–100, jpeg/webp/avif only.

waitUntil'auto' | 'load' | 'domcontentloaded' | 'networkidle'

Navigation wait condition. Default "auto": waits for load, then for the network to be quiet for 150ms, capped at 400ms. "networkidle" is the full wait and costs ~0.5s more.

waitForSelectorstring

Wait for this selector before capturing.

delayMsinteger

Extra settle time, 0–30000.

scrollYinteger

Scroll down first, to trigger lazy loading.

hideSelectorsstring

Comma-separated selectors to hide.

darkMode'true' | 'false' | '1' | '0' | 'prefers' | 'force'

true/force emulate prefers-color-scheme: dark AND turn on Chromium's auto dark mode, so a site with no dark theme still comes back dark (a site that has one is left alone). prefers is the media query only.

dismissBanners'true' | 'false' | '1' | '0'

Hide known cookie/consent banners (default true).

blockAds'true' | 'false' | '1' | '0'

Abort ad/analytics/session-replay requests.

customCssstring

URL-encoded CSS injected after load.

customJsstring

URL-encoded JS evaluated after load.

cache'true' | 'false' | '1' | '0'

Set false to force a fresh render.

responseType'binary' | 'json'

json answers with a hosted URL instead of bytes.

pdf.formatstring

Paper size. Flat alias: pdfFormat.

pdf.landscape'true' | 'false' | '1' | '0'

Landscape orientation. Flat alias: pdfLandscape.

pdf.printBackground'true' | 'false' | '1' | '0'

Print background graphics. Flat alias: pdfPrintBackground.

pdf.scalenumber

0.1–2. Flat alias: pdfScale.

pdf.preferCSSPageSize'true' | 'false' | '1' | '0'

Honour the page's @page size. Flat alias: pdfPreferCSSPageSize.

pdf.marginstring

One CSS length applied to all four sides. Per-side: pdf.margin.top … or pdfMarginTop ….

pdf.headerTemplatestring

HTML drawn at the top of every page. Flat alias: pdfHeaderTemplate.

pdf.footerTemplatestring

HTML drawn at the bottom of every page, or a preset name (@pageNumbers, @pageNumbersUrl). Setting it turns displayHeaderFooter on. Flat alias: pdfFooterTemplate.

pdf.displayHeaderFooter'true' | 'false' | '1' | '0'

Draw the running header/footer. Inferred from the templates. Flat alias: pdfDisplayHeaderFooter.

pdf.pageRangesstring

Sheets to keep — 1-3, 1,4,7-9. Flat alias: pdfPageRanges.

pdf.media'print' | 'screen'

Stylesheet the paper is printed under. Default print. Case-insensitive. Flat alias: pdfMedia.

pdf.tagged'true' | 'false' | '1' | '0'

Emit a tagged (accessible) PDF. Flat alias: pdfTagged.

pdf.outline'true' | 'false' | '1' | '0'

Embed a document outline (bookmarks). Flat alias: pdfOutline.

pdf.widthstring

Exact paper width as a CSS length; replaces pdf.format and needs pdf.height too. Flat alias: pdfWidth.

pdf.heightstring

Exact paper height as a CSS length. Flat alias: pdfHeight.

pdf.omitBackground'true' | 'false' | '1' | '0'

Drop background colours and images. Flat alias: pdfOmitBackground.

filenamestring

Suggested download name, sanitised — sets content-disposition on the response.

keyIdstring

API key id, for a signed URL. Send with sig.

sigstring

hex(HMAC_SHA256(signingSecret, canonicalQuery)) over every pair except sig, sorted by name then value.

expiresinteger

Optional Unix-seconds expiry, included in the signed canonical string.

Response

The rendered bytes.

urlstring uri required
idstring required
formatstring required
widthinteger
heightinteger
bytesinteger required
cacheHitboolean
durationMsinteger

Example response

{
  "url": "https://snaplab.dev/i/c/V1StGXR8_Z5j",
  "id": "V1StGXR8_Z5j",
  "format": "png"
}

Changes

No recorded changes to this operation across all 1 revision of this API.