Skip to content

Short and long screenshots have different widths despite setDeviceMetricsOverride #84

Closed

Description

@bersbersbers

This may be the chromote-only version of rstudio/shinytest2#171 (using chromote 865e24e).

b <- chromote::ChromoteSession$new()
b$Emulation$setDeviceMetricsOverride(width=1920, height=1080, deviceScaleFactor=1, mobile=FALSE)

b$Page$navigate("https://www.google.com/search?q=abc")
Sys.sleep(3)
b$screenshot("snap_long.png")

# b$Page$navigate("https://google.com/404")
# Sys.sleep(3)
# b$screenshot("snap_short.png")

Both snapshots should be 1920 pixels wide, but snap_short.png (for whatever reason - not the longer one!) comes out 1890 pixels wide. [Update: The shorter 404 one's dimenions are due to the HTML element having a 15-pixel-wide padding on both sides, which is not included in screenshots, and can be fixed by passing region="padding" to b$screenshot. See below for an updated example.]

I thought I had a solution for this while working on other issues (involving 05586e3 and/or b$Emulation$setScrollbarsHidden(TRUE) near b$Emulation$setDeviceMetricsOverride, but I cannot currently reproduce that. (see below)

Activity

  1. bersbersbers commented on Apr 6, 2022

    @bersbersbers
    ContributorAuthor

    This is what I was looking for:

    library(chromote)
    b <- ChromoteSession$new()
    b$Emulation$setDeviceMetricsOverride(width = 1920, height = 1080, deviceScaleFactor = 1, mobile = FALSE)
    b$Page$navigate("https://github.com/rstudio/chromote")
    Sys.sleep(3)
    b$screenshot("snap.png")

    This snapshot comes out at width 1905 and may be the closest case to rstudio/shinytest2#171, and it is the case which is actually fixed by b$Emulation$setScrollbarsHidden(TRUE), somewhat regardless of where one puts it.

    library(chromote)
    b <- ChromoteSession$new()
    # b$Emulation$setScrollbarsHidden(TRUE) # works
    b$Emulation$setDeviceMetricsOverride(width = 1920, height = 1080, deviceScaleFactor = 1, mobile = FALSE)
    # b$Emulation$setScrollbarsHidden(TRUE) # works
    b$Page$navigate("https://github.com/rstudio/chromote")
    b$Emulation$setScrollbarsHidden(TRUE) # works
    Sys.sleep(3)
    b$screenshot("snap.png")

    This snapshot is 1920 pixels wide, as expected. Interestingly, screenshot() does call setScrollbarsHidden already, but that call seems to be ineffective for some reason:

    p <- self$Emulation$setScrollbarsHidden(hidden = TRUE, wait_ = FALSE)$

  2. hadley commented on Jan 30, 2024

    @hadley
    Member

    Closing, since it seems like you figured out a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions