The perform_with_chrome() function executes an asynchronous Chrome DevTools Protocol flow with Chromium/Chrome and can turn it into a synchronous function. An asynchronous remote flow is a function that takes a connection object and returns a promise. If several functions are passed to perform_with_chrome(), their execution is serial. If one of the asynchronous functions fails, the whole execution also fails.

perform_with_chrome(
  ...,
  .list = NULL,
  timeouts = 30,
  cleaning_timeout = 30,
  async = FALSE,
  bin = NULL,
  debug_port = 9222L,
  local = FALSE,
  extra_args = NULL,
  headless = TRUE,
  retry_delay = 0.2,
  max_attempts = 15L
)

Arguments

...

Asynchronous remote flow functions.

.list

A list of asynchronous remote flow functions - an alternative to ....

timeouts

A vector of timeouts applied to each asynchronous function. Repeated.

cleaning_timeout

The delay for cleaning Chrome.

async

Is the result a promise? Required for using perform_with_chrome() in Shiny.

bin

Character scalar, the path to Chromium or Chrome executable. If not provided, crrri will try to find the chrome binary itself using find_chrome_binary(). You can set a path in HEADLESS_CHROME environment variable to indicate where it is located.

debug_port

Integer scalar, the Chromium/Chrome remote debugging port.

local

Logical scalar, indicating whether the local version of the protocol (embedded in crrri) must be used or the protocol must be fetched remotely.

extra_args

Character vector, extra command line arguments passed to Chromium/Chrome. You can know more about command line flags (or switches) from chromium developers

headless

Logical scalar, indicating whether Chromium/Chrome is launched in headless mode.

retry_delay

Number, delay in seconds between two successive tries to connect to headless Chromium/Chrome.

max_attempts

Logical scalar, number of tries to connect to headless Chromium/Chrome.

Value

An invisible list with the values of the fulfilled promises for each async function.d If there is only async function, the return value is the value of the fulfilled promise.

Examples

if (FALSE) { async_save_as_pdf <- function(url) { function(client) { Page <- client$Page Page$enable() %...>% { Page$navigate(url = url) Page$loadEventFired() } %...>% { Page$printToPDF() } %...>% { write_base64(., paste0(httr::parse_url(url)$hostname, ".pdf")) } } } save_as_pdf <- function(...) { list(...) %>% purrr::map(async_save_as_pdf) %>% perform_with_chrome(.list = .) } save_as_pdf("https://www.r-project.org/", "https://rstudio.com/") }