Home

stencila snap

Capture screenshots and measurements of documents served by Stencila

The snap command allows programmatic screenshotting and measurement of pages served by Stencila. It can be used to:

  • Iterate on themes and styled elements and verify changes - Capture screenshots for documentation or CI - Assert computed CSS properties and layout metrics - Measure page elements for automated testing - Extract resolved CSS custom property (theme token) values - Extract the page's color palette - Compare across device viewports using --device

Usage

stencila snap [OPTIONS] [ROUTE_OR_PATH]

Examples

# Snap site root (default route /)
stencila snap --shot homepage.png

# Extract resolved theme token values
stencila snap --tokens

# Extract color palette
stencila snap --palette

# Snap a specific site route with site chrome measurements
stencila snap /docs/guide/ --measure site

# Measure theme-critical regions with grouped color tokens
stencila snap --measure theme --tokens --token-prefix color

# Snap a document file directly
stencila snap ./my-doc.md --shot doc.png

# Assert site chrome properties
stencila snap --assert "exists(stencila-logo)==true"

# Full page dark mode screenshot
stencila snap --dark --full --shot dark-full.png

# Combined: tokens + palette + measurements for theme review
stencila snap --tokens --palette --measure all

# Verify theme token on header
stencila snap --assert "css(stencila-layout > header).backgroundColorHex==#1a1a2e"

# Capture mobile viewport of specific element
stencila snap --device mobile --selector "stencila-article [slot=title]" --shot mobile.png

# Optimize screenshot size for lower image payload cost
stencila snap --shot page.png --resize optimize --max-image-dimension 4096

Arguments

NameDescription
[ROUTE_OR_PATH]Route or path to snap.

Options

NameDescription
--shotScreenshot output path (.png).
--selectorCSS selector to capture or measure.
--fullCapture full scrollable page. Possible values: true, false.
--deviceDevice preset.
--widthViewport width in pixels.
--heightViewport height in pixels.
--dprDevice pixel ratio.
--resizeScreenshot resize mode: never, auto, optimize. Possible values: never, auto, optimize. Default value: auto.
--max-image-dimensionMaximum screenshot dimension in pixels after resize.
--lightUse light color scheme. Possible values: true, false.
--darkUse dark color scheme. Possible values: true, false.
--printPreview with print media styles (A4 width, for PDF preview). Possible values: true, false.
--wait-untilWhen to capture: load, domcontentloaded, networkidle. Default value: network-idle.
--wait-forWait for CSS selector to exist before capturing.
--delayAdditional delay in milliseconds after page is ready.
--measureCollect computed CSS and layout metrics.
--tokensExtract resolved CSS custom property (theme token) values. Possible values: true, false.
--token-prefixFilter extracted tokens by CSS custom property prefix.
--paletteExtract the page's color palette. Possible values: true, false.
--assertAssert measurement conditions.
--urlOverride URL (instead of discovering server).

Possible values of --measure

ValueDescription
autoAuto-select based on target type (route → site, path → document)
documentDocument content selectors
siteSite chrome selectors
allBoth document and site selectors
headerHeader and top-bar selectors
navNavigation and breadcrumb selectors
mainMain content selectors
footerFooter selectors
themeCombined theme review selectors

Possible values of --device

ValueDescription
laptopLaptop (1440x900 DPR)
desktopDesktop (1920x1080 DPR)
mobileMobile (390x844 DPR)
tabletTablet (768x1024 DPR)
tablet-landscapeTablet Landscape (1024x768 DPR)

Possible values of --wait-until

ValueDescription
loadWait for 'load' event
dom-content-loadedWait for 'DOMContentLoaded' event
network-idleWait for network idle (default)
© 2026 Stencila