Full webpage in webshot without manually altering dimensions
TimTaylor opened this issue · comments
For some webpages webshot
automatically captures the entire page without needing to manually alter the vwidth and vheight parameters.
For example the following, relatively small page gets cropped
webshot2::webshot("https://purrr.tidyverse.org/reference/index.html")
but the larger article below is captured fully
webshot2::webshot("https://www.bbc.co.uk/news/science-environment-49893849")
I'm guessing this is down to the different styles of the sites but is there anyway to automate the setting of vwidth and vheight to obtain the full page?
The starting vwidth
and vheight
size is 992x744 pixels. Just before taking a screenshot, webshot2 tries to size the vwidth
and vheight
to match the size of the body. However, for the purrr page, the height of the body is automatically sized to fit the viewport.
In this screenshot of my browser, you can see that the computed height of the body is just 336 pixels:
However, this div inside of the body has a height of 3704 pixels:
That div and its parent are sized using CSS flexbox. Perhaps there's some way of detecting when flex is used and size the viewport accordingly, but I have a feeling many flexbox layouts would trip it up -- that is, you wouldn't want the screenshot to automatically expand to fit all the flex elements.
A similar question came up here regarding gt::gtsave() (underlying webshot2::webshot()).
library(gt)
data.frame(replicate(20, runif(20L))) |>
gt() |>
gtsave("gt.png")
browseURL("gt.png")
Edit: just saw this related issue.