Chrome: Launch Chromium or Chrome

Description Usage Arguments Details Examples

Description

This class aims to launch Chromium or Chrome in headless mode. It possesses methods to manage connections to headless Chromium/Chrome using the Chrome Debugging Protocol.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
remote <- Chrome$new(bin = NULL, debug_port = 9222L,
                     local = FALSE, extra_args = NULL, headless = TRUE,
                     retry_delay = 0.2, max_attempts = 15L)

remote$connect(callback = NULL)
remote$listConnections()
remote$closeConnections(callback = NULL)
remote$version()
remote$user_agent

remote$close(async = FALSE)
remote$view()
remote$is_alive()

Arguments

Details

$new() opens a new headless Chromium/Chrome. You can deactivate verbose from chrome process launching byt setting option crrri.verbose to FALSE.

$connect(callback = NULL) connects the R session to the remote instance of headless Chromium/Chrome. The returned value depends on the value of the callback argument. When callback is a function, the returned value is a connection object. When callback is NULL the returned value is a promise which fulfills once R is connected to the remote instance of Chromium/Chrome. Once fulfilled, the value of this promise is the connection object.

$listConnections() returns a list of the connection objects succesfully created using the $connect() method.

$closeConnections(callback = NULL) closes all the connections created using the $connect() method. If callback is NULL, it returns a promise which fulfills when all the connections are closed: once fulfilled, its value is the remote object. If callback is not NULL, it returns the remote object. In this case, callback is called when all the connections are closed and the remote object is passed to this function as the argument.

$version() executes the DevTools Version method. It returns a list of informations available at http://localhost:<debug_port>/json/version.

$user_agent returns a character scalar with the User Agent of the headless Chromium/Chrome.

$close(async = FALSE) closes the remote instance of headless Chromium/Chrome. If async is FALSE this method returns the remote object invisibly. Is async is TRUE, a promise is returned. This promise fulfills when Chromium/Chrome is closed. Once fulfilled, its value is the remote object.

$view() opens a visible Chromium/Chrome browser at http://localhost:<debug_port>. This is useful to 'see' the headless Chromium/Chrome instance. Returns the process of the visible browser.

$is_alive() checks if the remote instance is alive. Returns a logical scalar.

$listTargets() returns a list with information about tabs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Not run: 

remote <- Chrome$new()

remote$connect() %...>% (function(client) {
  Page <- client$Page
  Runtime <- client$Runtime

  Page$enable() %...>% {
    Page$navigate(url = 'http://r-project.org')
  } %...>% {
    Page$loadEventFired()
  } %...>% {
    Runtime$evaluate(
      expression = 'document.documentElement.outerHTML'
    )
  } %...>% (function(result) {
    cat(result$result$value, "\n")
  })
}) %...!% {
  cat("Error:", .$message, "\n")
} %>%
  promises::finally(~ remote$close())

## End(Not run)

RLesur/crrri documentation built on March 20, 2021, 8:47 a.m.