Add per-viewport deviceScaleFactor (DPR) support#47
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional per-viewport
deviceScaleFactor(device pixel ratio) toreglance.json, so pages can be screenshotted as they appear on retina / high-density displays.What changed
src/config.mjs) —validateViewportsaccepts an optionaldeviceScaleFactor, validated as a positive number (fractional ratios like1.5allowed). Defaults to1when omitted.src/capture.mjs) — Playwright can only setdeviceScaleFactorat context creation, so captures are now grouped one browser context per DPR (newgroupViewportsByScaleFactorhelper) rather than one per viewport. Viewports usually share a ratio, so this is cheaper while still lettingsetViewportSizeswitch sizes within a group. First viewport in each context navigates fresh; the rest reuse the page (reloading unless--skip-reload).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.mobile-retinaviewport.Caveat worth noting
A
2×capture has double the pixel dimensions of its1×counterpart, so introducing or changing a viewport'sdeviceScaleFactorwill diff as fully changed untilreglance controlis re-run. Give retina variants distinct viewport names (e.g.mobilevsmobile-retina) since slugs are{key}-{viewport}.Testing
npm run lintclean (0 errors) andnpm test— 91 tests pass, including new coverage for the grouping helper, config validation, and report rendering (annotated vs clean).🤖 Generated with Claude Code