1

When I try running an asynchronous function with crrri, I receive the error message: "Error: Cannot launch Chrome. Please add the path to your Chrome bin."

I guess the error message is trying to tell me that crrri cannot find my chrome executable. So I tried by adding the following code above my function definition (to the global env)

chrome <- Chrome$new(bin = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", debug_port = 9224L)

but the error message stayed the same.

This is the code I am trying to run:

library(crrri)
print_pdf <- function(client) {
  Page <- client$Page
  Page$enable() %...>% {
    Page$navigate(
     url = "https://r-project.org/"
    )
    # await the load event
    Page$loadEventFired()
  } %...>% {
     Page$printToPDF() 
  } %...>% # await PDF reception
    write_base64("r_project.pdf")
}
# To modify depending on the page 
# content (JS libraries…)
perform_with_chrome(print_pdf)

The expected result would be a printed website to a pdf file saved to my PWD.

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
Tea Tree
  • 882
  • 11
  • 26

1 Answers1

1

As I suspected, the function was calling on HEADLESS_CHROME path which it was looking for in the global environment. I checked this by running Sys.getenv(HEADLESS_CHROME) which came back empty.

To change this, I imported the decapitated package and used set_chrome_env() as follows:

#install.packages("decapitated")
library(decapitated)
set_chrome_env(env = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")

This set the path to my Chrome executable and all subsequent functions worked.

The manual of crrri states that "you can use the bin argument of the chr_connect() function." but I haven't figured out how to do that.

Tea Tree
  • 882
  • 11
  • 26