Pixel-level screenshot comparison using the pixelmatch algorithm. Runs inside Playwright's Canvas API — no AWT/ImageIO dependency, GraalVM native-image safe.
Based on pixelmatch by Mapbox (ISC license): https://github.com/mapbox/pixelmatch
Pixel-level screenshot comparison using the pixelmatch algorithm. Runs inside Playwright's Canvas API — no AWT/ImageIO dependency, GraalVM native-image safe. Based on pixelmatch by Mapbox (ISC license): https://github.com/mapbox/pixelmatch
(compare-pages baseline-page current-page & {:as opts})Screenshot + snapshot + diff in one call. Takes two live Playwright pages, captures screenshots and accessibility snapshots from both, then runs pixel diff with semantic region enrichment.
This is the highest-level diff function — produces fully enriched regions with element labels like "button 'Submit' — content-change".
Options: same as compare-screenshots (threshold, include-aa, etc.)
Returns: same as compare-screenshots, with enriched regions, plus: :baseline-snapshot - accessibility tree of baseline page :current-snapshot - accessibility tree of current page
Screenshot + snapshot + diff in one call. Takes two live Playwright pages, captures screenshots and accessibility snapshots from both, then runs pixel diff with semantic region enrichment. This is the highest-level diff function — produces fully enriched regions with element labels like "button 'Submit' — content-change". Options: same as compare-screenshots (threshold, include-aa, etc.) Returns: same as compare-screenshots, with enriched regions, plus: :baseline-snapshot - accessibility tree of baseline page :current-snapshot - accessibility tree of current page
(compare-screenshot-files baseline-path current-path & opts)Compare two PNG screenshot files. See compare-screenshots for options.
Compare two PNG screenshot files. See compare-screenshots for options.
(compare-screenshots baseline
current
&
{:keys [threshold include-aa alpha denoise dilate
merge-distance diff-path baseline-refs
current-refs]
:or {threshold 0.1
include-aa false
alpha 0.5
denoise 25
dilate 3
merge-distance 50}})Compare two PNG screenshots pixel-by-pixel using the pixelmatch algorithm (YIQ NTSC color space with anti-aliasing detection).
Runs the comparison inside Playwright's Canvas API — no AWT/ImageIO, GraalVM native-image safe.
baseline and current are PNG byte arrays (as returned by page/screenshot).
Options: :threshold — matching threshold 0.0-1.0 (default 0.1, lower = stricter) :include-aa — count anti-aliased pixels as diff (default false) :alpha — red overlay opacity on changed pixels (default 0.5) :denoise — minimum connected-component pixels to keep (default 25) :dilate — dilation radius in pixels before component labeling (default 3) :merge-distance — merge nearby region boxes within this many pixels (default 50) :diff-path — optional path to save the diff image PNG :baseline-refs — snapshot refs map for baseline state (optional, from capture-snapshot :refs) :current-refs — snapshot refs map for current state (optional, from capture-snapshot :refs) When provided, regions are enriched with semantic element labels.
Returns: {:matched true/false :diff-count number of different pixels :total-pixels total pixel count :diff-percent percentage of different pixels (2 decimal places) :width comparison width :height comparison height :regions [{:id n :label "added|removed|content-change" :pixels n :bounding-box {:x n :y n :width n :height n} :element {:ref s :role s :name s :overlap n} :elements [{:ref s :role s :name s :overlap n}] :semantic-label s} ...] :diff-image diff PNG as byte[] :baseline-dimensions {:width w :height h} :current-dimensions {:width w :height h} :dimension-mismatch true/false}
Compare two PNG screenshots pixel-by-pixel using the pixelmatch algorithm
(YIQ NTSC color space with anti-aliasing detection).
Runs the comparison inside Playwright's Canvas API — no AWT/ImageIO,
GraalVM native-image safe.
`baseline` and `current` are PNG byte arrays (as returned by page/screenshot).
Options:
:threshold — matching threshold 0.0-1.0 (default 0.1, lower = stricter)
:include-aa — count anti-aliased pixels as diff (default false)
:alpha — red overlay opacity on changed pixels (default 0.5)
:denoise — minimum connected-component pixels to keep (default 25)
:dilate — dilation radius in pixels before component labeling (default 3)
:merge-distance — merge nearby region boxes within this many pixels (default 50)
:diff-path — optional path to save the diff image PNG
:baseline-refs — snapshot refs map for baseline state (optional, from capture-snapshot :refs)
:current-refs — snapshot refs map for current state (optional, from capture-snapshot :refs)
When provided, regions are enriched with semantic element labels.
Returns:
{:matched true/false
:diff-count number of different pixels
:total-pixels total pixel count
:diff-percent percentage of different pixels (2 decimal places)
:width comparison width
:height comparison height
:regions [{:id n :label "added|removed|content-change" :pixels n
:bounding-box {:x n :y n :width n :height n}
:element {:ref s :role s :name s :overlap n}
:elements [{:ref s :role s :name s :overlap n}]
:semantic-label s} ...]
:diff-image diff PNG as byte[]
:baseline-dimensions {:width w :height h}
:current-dimensions {:width w :height h}
:dimension-mismatch true/false}(enrich-regions regions refs)Enriches diff regions with semantic labels from accessibility snapshot refs.
regions - vector of diff regions from compare-screenshots
refs - snapshot refs map from capture-snapshot (:refs key)
Format: {e2yrjz {:role button :name Submit :bbox {:x :y :width :height}} ...}
Returns the regions vector with additional keys on each region: :element - best matching element {:ref :role :name :overlap} :elements - all overlapping elements sorted by specificity :semantic-label - human-readable label like button 'Submit' — content-change
Enriches diff regions with semantic labels from accessibility snapshot refs.
`regions` - vector of diff regions from compare-screenshots
`refs` - snapshot refs map from capture-snapshot (:refs key)
Format: {e2yrjz {:role button :name Submit :bbox {:x :y :width :height}} ...}
Returns the regions vector with additional keys on each region:
:element - best matching element {:ref :role :name :overlap}
:elements - all overlapping elements sorted by specificity
:semantic-label - human-readable label like button 'Submit' — content-changecljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |