Skip to content

Add per-viewport deviceScaleFactor (DPR) support#47

Merged
jeremyfelt merged 1 commit into
trunkfrom
add-device-scale-factor
Jun 9, 2026
Merged

Add per-viewport deviceScaleFactor (DPR) support#47
jeremyfelt merged 1 commit into
trunkfrom
add-device-scale-factor

Conversation

@jeremyfelt

Copy link
Copy Markdown
Member

Summary

Adds an optional per-viewport deviceScaleFactor (device pixel ratio) to reglance.json, so pages can be screenshotted as they appear on retina / high-density displays.

"viewports": [
  { "name": "desktop", "width": 1920, "height": 1080 },
  { "name": "mobile", "width": 390, "height": 844 },
  { "name": "mobile-retina", "width": 390, "height": 844, "deviceScaleFactor": 2 }
]

What changed

  • Config (src/config.mjs)validateViewports accepts an optional deviceScaleFactor, validated as a positive number (fractional ratios like 1.5 allowed). Defaults to 1 when omitted.
  • Capture (src/capture.mjs) — Playwright can only set deviceScaleFactor at context creation, so captures are now grouped one browser context per DPR (new groupViewportsByScaleFactor helper) rather than one per viewport. Viewports usually share a ratio, so this is cheaper while still letting setViewportSize switch sizes within a group. First viewport in each context navigates fresh; the rest reuse the page (reloading unless --skip-reload).
  • Report UI (src/report.mjs + templates) — the ratio is surfaced as a @2x-style suffix in the index table, the viewport filter dropdown, the per-comparison report, and the HTML-diff report. Shown only for non-default ratios, so standard captures stay clean.
  • Docs — README viewport row + a note covering retina usage, context grouping, and the re-baseline caveat; example config gains a mobile-retina viewport.

Caveat worth noting

A capture has double the pixel dimensions of its counterpart, so introducing or changing a viewport's deviceScaleFactor will diff as fully changed until reglance control is re-run. Give retina variants distinct viewport names (e.g. mobile vs mobile-retina) since slugs are {key}-{viewport}.

Testing

npm run lint clean (0 errors) and npm test — 91 tests pass, including new coverage for the grouping helper, config validation, and report rendering (annotated vs clean).

🤖 Generated with Claude Code

Viewports may now set an optional `deviceScaleFactor` (device pixel
ratio) so pages can be captured as they appear on retina / high-density
displays. It defaults to 1, validates as a positive number (fractional
ratios like 1.5 are allowed), and is documented in the README and
example config.

Because Playwright can only set deviceScaleFactor when a context is
created, captures are grouped one browser context per DPR rather than
one per viewport — viewports usually share a ratio, so this is cheaper
while still letting setViewportSize switch sizes within a group.

The ratio is surfaced in the report UI (index table, viewport filter,
per-comparison report, and HTML-diff report) as a ` @2x`-style suffix,
shown only for non-default ratios so standard captures stay clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jeremyfelt
jeremyfelt merged commit d955e34 into trunk Jun 9, 2026
2 checks passed
@jeremyfelt
jeremyfelt deleted the add-device-scale-factor branch June 9, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant