rstudio / webshot2

Take screenshots of web pages from R

Home Page:https://rstudio.github.io/webshot2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Edge browser when webshot()?

kangjf1943 opened this issue · comments

commented

I use Edge browser, without Chrome on my mac. I tried the example code in the help document, webshot("http://rstudio.github.io/leaflet", delay = 0.5), and it said:

Error in rethrow_call(c_processx_exec, command, c(command, args), pty,  :  
cannot start processx process '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' (system error 2, No such file or directory) @unix/processx.c:610 (processx_exec)

Then I installed Chrome, and the code works perfectly. But I wonder if it is possible to change the default browser of webshot() to Edge browser (with no Chrome installed on the mac)? Here, though, it says, "You also need to have the Chrome browser installed on your system. You can also use other browsers based on Chromium, such as Chromium itself, Edge, Vivaldi, Brave, or Opera."

Hi @kangjf1943! webshot2 uses the chromote R package behind the scenes to find and interact with headless Chrome. chromote::find_chrome() is the function used to return the path to the chrome binary used by chromote.

chromote::find_chrome()
#> [1] "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

To use Edge, you can set the CHROMOTE_CHROME environment variable to point to the Edge executable. You can do this locally (as below), or you can add CHRMOTE_CHROME=<path> to your global .Renviron file (see usethis::use_r_environ()).

Sys.setenv(CHROMOTE_CHROME = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge")
chromote::find_chrome()
#> [1] "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
webshot2::webshot("http://rstudio.github.io/leaflet", delay = 0.5)
commented

Hi @gadenbuie thank you for your reply. I tried to make it locally, but failed:

chromote::find_chrome()
# original output:
# [1] "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
# then change the CHROMOTE_CHROME
Sys.setenv(
  CHROMOTE_CHROME = 
    "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
)
chromote::find_chrome()
# output: 
# [1] "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
webshot2::webshot("http://rstudio.github.io/leaflet", delay = 0.5)
# Error in s$close() : attempt to apply non-function
sessionInfo()
# R version 4.1.2 (2021-11-01)
# Platform: x86_64-apple-darwin17.0 (64-bit)
# Running under: macOS Monterey 12.3.1
# 
# Matrix products: default
# LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
# 
# locale:
#   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] webshot2_0.1.0    mapview_2.11.0    kableExtra_1.3.4  knitr_1.41        magrittr_2.0.3   
# [6] aod_1.3.2         showtext_0.9-4    showtextdb_3.0    sysfonts_0.8.5    tmap_3.3-3       
# [11] ggplot2_3.4.0     tidyr_1.2.1       data.table_1.14.6 dplyr_1.0.10      geojsonsf_2.0.3  
# [16] stars_0.6-0       abind_1.4-5       raster_3.6-14     sp_1.5-1          sf_1.0-9         
# [21] stringr_1.5.0     lubridate_1.9.0   timechange_0.1.1  readr_2.1.3       targets_0.14.2   
# 
# loaded via a namespace (and not attached):
#   [1] websocket_1.4.1         leafem_0.2.0            colorspace_2.0-3       
# [4] ellipsis_0.3.2          class_7.3-19            leaflet_2.1.1          
# [7] rgdal_1.5-29            rprojroot_2.0.3         satellite_1.0.4        
# [10] base64enc_0.1-3         fs_1.5.2                dichromat_2.0-0.1      
# [13] rstudioapi_0.13         proxy_0.4-27            farver_2.1.1           
# [16] bit64_4.0.5             chromote_0.1.1          fansi_1.0.3            
# [19] xml2_1.3.3              codetools_0.2-18        splines_4.1.2          
# [22] cachem_1.0.6            jsonlite_1.8.4          tmaptools_3.1-1        
# [25] png_0.1-8               httr_1.4.4              compiler_4.1.2         
# [28] backports_1.4.1         assertthat_0.2.1        Matrix_1.5-1           
# [31] fastmap_1.1.0           cli_3.5.0               later_1.3.0            
# [34] s2_1.1.1                leaflet.providers_1.9.0 htmltools_0.5.4        
# [37] tools_4.1.2             igraph_1.2.11           gtable_0.3.1           
# [40] glue_1.6.2              wk_0.7.1                Rcpp_1.0.9             
# [43] jquerylib_0.1.4         vctrs_0.5.1             svglite_2.1.0          
# [46] nlme_3.1-153            leafsync_0.1.0          crosstalk_1.2.0        
# [49] lwgeom_0.2-8            xfun_0.36               ps_1.6.0               
# [52] rvest_1.0.3             lifecycle_1.0.3         XML_3.99-0.9           
# [55] terra_1.6-41            scales_1.2.1            vroom_1.6.0            
# [58] hms_1.1.2               promises_1.2.0.1        parallel_4.1.2         
# [61] RColorBrewer_1.1-3      yaml_2.3.6              sass_0.4.4             
# [64] stringi_1.7.8           highr_0.10              e1071_1.7-12           
# [67] systemfonts_1.0.4       rlang_1.0.6             pkgconfig_2.0.3        
# [70] evaluate_0.19           lattice_0.20-45         purrr_1.0.1            
# [73] htmlwidgets_1.5.4       labeling_0.4.2          bit_4.0.5              
# [76] processx_3.5.2          tidyselect_1.2.0        here_1.0.1             
# [79] bookdown_0.32           R6_2.5.1                generics_0.1.3         
# [82] base64url_1.4           DBI_1.1.3               pillar_1.8.1           
# [85] withr_2.5.0             mgcv_1.8-38             units_0.8-1            
# [88] tibble_3.1.8            crayon_1.5.2            KernSmooth_2.23-20     
# [91] utf8_1.2.2              tzdb_0.3.0              rmarkdown_2.19         
# [94] usethis_2.1.6           grid_4.1.2              callr_3.7.0            
# [97] webshot_0.5.3           digest_0.6.31           classInt_0.4-8         
# [100] stats4_4.1.2            munsell_0.5.0           viridisLite_0.4.1      
# [103] bslib_0.4.2 

Then I tried usethis::use_r_environ() but:

usethis::use_r_environ()
# Error: 'use_r_environ' is not an exported object from 'namespace:usethis'

I thought that might be related to version of usethis so I re-installed it, however, that doesn't change the output.

Thanks for your time.

I have the same problem, but on windows:
library(webshot2)
Sys.setenv(CHROMOTE_CHROME = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
chromote::find_chrome()
#[1] "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
webshot2::webshot("http://rstudio.github.io/leaflet", delay = 0.5)
#Error in launch_chrome(path, args) :
#Chrome debugging port not open after 10 seconds.

Any idea how to solve the problem? Thanks for your help

Just to share this is working for me

> library(webshot2)
> Sys.setenv(CHROMOTE_CHROME = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
> chromote::find_chrome()
[1] "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
> webshot2::webshot("http://rstudio.github.io/leaflet", delay = 0.5)
http://rstudio.github.io/leaflet screenshot completed

with

> packageVersion("chromote")
[1] ‘0.1.1’
> packageVersion("webshot2")
[1] ‘0.1.0’

on Windows 10 with Edge Version 114.0.1823.58

ah o.k. then this is a proxy problem. tried it at home and it works. Thanks for the help :)