CDPRemote: Declare a remote application implementing the Chrome...

Description Usage Arguments Details Examples

Description

This class aims to declare an application implementing the Chrome Debugging Protocol. It possesses methods to manage connections.

Usage

1
2
3
4
5
6
7
8
remote <- CDPRemote$new(host = "localhost", debug_port = 9222, secure = FALSE,
                        local = FALSE, retry_delay = 0.2, max_attempts = 15L)

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

Arguments

Details

$new() declares a new remote application.

$connect(callback = NULL) connects the R session to the remote application. 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 application. 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://<host>:<debug_port>/json/version.

$user_agent returns a character scalar with the User Agent of the remote application.

$listTargets() returns a list with information about targets (or 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
26
27
28
29
30
## Not run: 
# Assuming that an application is already running at http://localhost:9222
# For instance, you can execute:
# chrome <- Chrome$new()

remote <- CDPRemote$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(~ client$disconnect())
}) %...!% {
  cat("Error:", .$message, "\n")
}

## End(Not run)

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