Repository navigation
Take screenshots beyond viewport without resizing - #83
Conversation
|
Interesting -- this should really simplify the screenshotting process. I believe that the A couple things to watch out for:
|
|
@wch Why was this PR closed? |
|
Oh oops, I must have accidentally clicked that. |
Yes, this landed in Chrome 89, and the code I deleted refers to Chrome 72 and 75.
Do you mean vertically, horizontally, both?
I filed (in principle, unrelated) issues as the current implementation has problems in exactly these cases, see rstudio/shinytest2#171 and #84 |
I was thinking vertically (which would be far more common), although I suppose it's good to know what happens if it's smaller horizontally as well. The reason I ask is because the existing behavior would take a screenshot that is the same size of the page, but I think that the new behavior would be to take a screenshot that is larger than the page. (Just guessing; I haven't tried this out myself.) |
Understood. I would have to try that out myself, too: I never use it without Lines 51 to 54 in 865e24e |
|
A few more points in addition:
|
|
All theoretical considerations aside, a short test reveals that chromote already renders "small" (short, narrow) web sites according the dimensions of the initial session (probably because the git clone https://github.com/bersbersbers/chromote/
cd chromote
export URL="https://cran.r-project.org/bin/"
export BRANCH="main"
# export BRANCH="snapshot_without_resize"
git checkout $BRANCH
Rscript -e 'devtools::install(); b <- chromote::ChromoteSession$new(); b$Page$navigate(Sys.getenv("URL")); Sys.sleep(1); b$screenshot("snap.png")'
exiftool snap.png | grep -E "Width|Height"I have not tested how |
The page you were using for testing is this one: https://cran.r-project.org/bin/ With this app, the body does not fill the height of the viewport. And currently, screenshots of that page result in a PNG that is 463 pixels tall. library(chromote)
b <- chromote::ChromoteSession$new()
b$Page$navigate("https://gallery.shinyapps.io/001-hello/?showcase=0")
# Wait for a few seconds
b$screenshot() |
It is possible (though uncommon) for a web page to have the One thing that could be done is to use the The goal of the screenshot method is to get an image of the web page; if we are willing to capture areas that are outside of the viewport, then we should be willing to trim the image to match the web page. |
|
Now that we've been looking at the code more closely, it appears that the |
|
Been using this PR for the day and have not run into issues. I'd like to merge it as it solves a few issues in |
|
@bersbersbers Has this PR resolved the pixel diffs being produced in {shinytest2}? |
|
Merging before feedback. My local usage as been good! |
* main: Take screenshots beyond viewport without resizing (#83) Quote browser path if not using Windows (#80) Do not `shQuote()` the browser path (#78) `$view()` should use local `Chrome` browser if available (#73) Add a reasonable `{chromote}` wall `timeout_` if Protocol `timeout` exists (#69) Remove `ChromoteSession$get_parent()` and lock `$protocol` (#76)
Sorry for the late reply, I was OOO for a bit. With |
|
@bersbersbers Yay! Glad to hear |
This closes #81 and may also help with rstudio/shinytest2#136