yonicd / carbonate

carbon.js for R
https://yonicd.github.io/carbonate/
Other
211 stars 5 forks source link

Error on running `x$carbonate()` #29

Open Robinlovelace opened 2 years ago

Robinlovelace commented 2 years ago

Describe the bug

I got an error message when trying to create a carbonate screenshot for the first time.

To Reproduce

> ?carbonate::carbon
> x = carbonate::carbon$new("test")
> x$carbonate(file = "/tmp/test.png")
starting chrome session...
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
Creating directory: ~/.local/share/binman_chromedriver/linux64/100.0.4896.20
Downloading binary: https://www.googleapis.com/download/storage/v1/b/chromedriver/o/100....

Creating directory: ~/.local/share/binman_chromedriver/linux64/100.0.4896.60
Downloading binary: https://www.googleapis.com/download/storage/v1/b/chromedriver/o/100....

Creating directory: ~/.local/share/binman_chromedriver/linux64/101.0.4951.15
Downloading binary: https://www.googleapis.com/download/storage/v1/b/chromedriver/o/101....

BEGIN: POSTDOWNLOAD
Error in (function (platform, file, processed, chmod)  : 
  ~/.local/share/binman_geckodriver/linux64/0.31.0/geckodriver-v0.31.0-linux64.tar.gz.asc does not appear to be a zip or tar file.

Expected behavior

I expected to have an error message that provided indications of how to resolve the issue.

Session Info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.3 (2022-03-10) #> os Ubuntu 20.04.4 LTS #> system x86_64, linux-gnu #> ui X11 #> language en_US:en #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/London #> date 2022-04-18 #> pandoc 2.18 @ /usr/lib/rstudio/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> brio 1.1.3 2021-11-30 [3] CRAN (R 4.1.2) #> cachem 1.0.6 2021-08-19 [3] CRAN (R 4.1.1) #> callr 3.7.0 2021-04-20 [3] CRAN (R 4.0.5) #> cli 3.2.0 2022-02-14 [3] CRAN (R 4.1.2) #> crayon 1.5.1 2022-03-26 [3] CRAN (R 4.1.3) #> desc 1.4.1 2022-03-06 [1] CRAN (R 4.1.3) #> devtools 2.4.3 2021-11-30 [3] CRAN (R 4.1.2) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2) #> ellipsis 0.3.2 2021-04-29 [3] CRAN (R 4.0.5) #> evaluate 0.15 2022-02-18 [3] CRAN (R 4.1.2) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.1.3) #> fastmap 1.1.0 2021-01-25 [3] CRAN (R 4.0.3) #> fs 1.5.2 2021-12-08 [3] CRAN (R 4.1.2) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.3) #> highr 0.9 2021-04-16 [3] CRAN (R 4.0.5) #> htmltools 0.5.2 2021-08-25 [3] CRAN (R 4.1.1) #> knitr 1.38 2022-03-25 [1] CRAN (R 4.1.3) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [3] CRAN (R 4.1.3) #> memoise 2.0.1 2021-11-26 [3] CRAN (R 4.1.2) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.3) #> pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.2) #> pkgconfig 2.0.3 2019-09-22 [3] CRAN (R 4.0.0) #> pkgload 1.2.4 2021-11-30 [3] CRAN (R 4.1.2) #> prettyunits 1.1.1 2020-01-24 [3] CRAN (R 4.0.0) #> processx 3.5.3 2022-03-25 [3] CRAN (R 4.1.3) #> ps 1.6.0 2021-02-28 [3] CRAN (R 4.0.4) #> purrr 0.3.4 2020-04-17 [3] CRAN (R 4.0.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [3] CRAN (R 4.1.1) #> remotes 2.4.2 2021-11-30 [1] CRAN (R 4.1.2) #> reprex 2.0.1 2021-08-05 [3] CRAN (R 4.1.0) #> rlang 1.0.2 2022-03-04 [3] CRAN (R 4.1.3) #> rmarkdown 2.13 2022-03-10 [3] CRAN (R 4.1.3) #> rprojroot 2.0.3 2022-04-02 [3] CRAN (R 4.1.3) #> rstudioapi 0.13 2020-11-12 [3] CRAN (R 4.0.3) #> sessioninfo 1.2.2 2021-12-06 [3] CRAN (R 4.1.2) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.2) #> stringr 1.4.0 2019-02-10 [3] CRAN (R 4.0.0) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.1.3) #> testthat 3.1.3 2022-03-29 [1] CRAN (R 4.1.3) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.2) #> usethis 2.1.5 2021-12-09 [3] CRAN (R 4.1.2) #> utf8 1.2.2 2021-07-24 [3] CRAN (R 4.1.0) #> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.1.3) #> withr 2.5.0 2022-03-03 [3] CRAN (R 4.1.3) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.1.3) #> yaml 2.3.5 2022-02-21 [3] CRAN (R 4.1.2) #> #> [1] /home/robin/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ``` Created on 2022-04-18 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)
yonicd commented 2 years ago

It appears you do not have the expected version of the gecko driver installed that {binman} depends on, which handles requests for wdman, which in turn backends {RSelenium}, which drives {carbonate}.

~/.local/share/binman_geckodriver/linux64/0.31.0/geckodriver-v0.31.0-linux64.tar.gz.asc does not appear to be a zip or tar file.

RSelenium docs

what do you get when you run Sys.which('firefox')?

If it is '', then you will probably need to run: sudo apt-get install firefox

Robinlovelace commented 2 years ago

what do you get when you run Sys.which('firefox')?

Sys.which("firefox")
#>            firefox 
#> "/usr/bin/firefox"

Created on 2022-04-18 by the reprex package (v2.0.1)

yonicd commented 2 years ago

That’s good 👍.

What version is it?

are you able to run this example?

gDrv <- wdman::gecko(port = httpuv::randomPort())
gDrv$output()
gDrv$stop()
yonicd commented 2 years ago

Regardless though carbonate assumes you are running on a chrome driver. I don’t think it would run on a gecko.

https://github.com/yonicd/carbonate/blob/master/R/selenium_functions.R

Robinlovelace commented 2 years ago

Sure:

gDrv <- wdman::gecko(port = httpuv::randomPort())
#> checking geckodriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD
gDrv$output()
#> character(0)
gDrv$stop()
#> [1] TRUE

Created on 2022-04-18 by the reprex package (v2.0.1)

yonicd commented 2 years ago

Looks right. I’m away from a computer for the week. I’ll be able to dive deeper on the weekend. Your original error is weird. Seems like wdman downloaded the chrome driver but is erroring out on a gecko tar file in post download.

yonicd commented 2 years ago

I found the same frustrating error. It is something in the guts of RSelenium. After a a few days of futzing with it I finished up a long open PR that gets around the issue by supporting chrome and firefox for carbonate.

firefox is the default, and runs headless which makes things smoother from the end user perspective imo.

you can try it out, it is merged into the master branch. https://github.com/yonicd/carbonate/commit/c8f41c1fbbef0dad2f50edcedc404ddbfdff8b75

Robinlovelace commented 2 years ago

Wow! Amazing work by the sounds of it, will try soon, busy week though, many thanks :tada: