Description Usage Arguments Details Examples
This class aims to declare an application implementing the Chrome Debugging Protocol. It possesses methods to manage connections.
1 2 3 4 5 6 7 8 |
remote
: an object representing a remote application implementing the
Chrome Debugging Protocol.
host
: Character scalar, the host name of the application.
debug_port
: Integer scalar, the remote debugging port.
secure
: Logical scalar, indicating whether the https/wss protocols
shall be used for connecting to the remote application.
local
: Logical scalar, indicating whether the local version of the
protocol (embedded in crrri
) must be used or the protocol must be
fetched remotely.
retry_delay
: Number, delay in seconds between two successive tries to
connect to the remote application.
max_attempts
: Integer scalar, number of tries to connect to headless
Chromium/Chrome.
callback
: Function with one argument.
$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).
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.