fix: deviceScaleFactor = 0 disables the metric override#209
Merged
Conversation
which we then treat as `pixel_ratio = NULL`.
gadenbuie
commented
Mar 12, 2025
Member
Author
gadenbuie
left a comment
There was a problem hiding this comment.
Just a note that deviceScaleFactor basically overrides window.devicePixelRatio
pkgload::load_all()
#> ℹ Loading chromote
b <- ChromoteSession$new()
b$Runtime$evaluate("window.devicePixelRatio")$result$value
#> [1] 1
b$set_viewport_size(800, 800, zoom = 2)
b$Runtime$evaluate("window.devicePixelRatio")$result$value
#> [1] 2
b$set_viewport_size(800, 800, zoom = 1.25)
b$Runtime$evaluate("window.devicePixelRatio")$result$value
#> [1] 1.25where deviceScaleFactor = 0 is equivalent to removing any overrides, in which case we set private$pixel_ratio = NULL as a signal that we need to check in with the browser to know the current value.
b$set_viewport_size(800, 800, zoom = 0)
b$Runtime$evaluate("window.devicePixelRatio")$result$value
#> [1] 1
wch
reviewed
Mar 12, 2025
…eeded Co-authored-by: Winston Chang <winston@posit.co>
wch
approved these changes
Mar 12, 2025
3b67e0d to
20e213e
Compare
Member
Author
|
Merging so we get overnight tests in shinycoreci; the failing test is flaky and I'll follow up separately to address that. |
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.
Fixes rstudio/shinytest2#404
In rstudio/shinytest2#350, we went from using
deviceScaleFactor = 1before screenshots to usingdeviceScaleFactor = 0in theEmulation.setDeviceMetricsOverridecommand. As pointed out there, the CDP docs explain that this is equivalent to disabling deivce scaling.The issue rstudio/shinytest2#350 resolved was a problem that was flagged for us on CRAN that was difficult to reproduce. IIRC, we eventually realized that we were getting different screenshot sizes on Mac when the Chrome browser window was being displayed on a Retina display vs a monitor (and by association, the failing manual CRAN tests were happening on a laptop display).
That said, playwright defaults to
deviceScaleFactor = 1: https://github.com/microsoft/playwright/blob/3b9515e7efa07230684bef9704c601f509f8ad72/packages/playwright-core/src/server/chromium/crPage.ts#L964Anyway, for consistently sized screenshots, we may end up in a situation where we need to query
window.devicePixelRatioto find the current value (becausedeviceScaleFactorwas set to0).In retrospect, the real issue behind rstudio/shinytest2#350 was that we were calling
Emulation.setDeviceMetricsOverrideand settingdeviceScaleFactor = 1, but internally the screenshot method was still usingpixel_ratio = 2because we weren't tracking changes topixel_ratio. So usingdeviceScaleFactor = 0in shinytest2 was equivalent to not changing the pixel ratio.We could consider not tracking
pixel_ratioat all, but our current approach does save us a round trip call or two to the browser whenever we change the viewport size.