| Chromote {chromote} | R Documentation |
Chromote class
Description
A Chromote object represents the browser as a whole, and it can have
multiple targets, which each represent a browser tab. In the Chrome
DevTools Protocol, each target can have one or more debugging sessions to
control it. A ChromoteSession object represents a single session.
A Chromote object can have any number of ChromoteSession objects as
children. It is not necessary to create a Chromote object manually. You can
simply call:
b <- ChromoteSession$new()
and it will automatically create a Chromote object if one has not already
been created. The chromote package will then designate that Chromote
object as the default Chromote object for the package, so that any future
calls to ChromoteSession$new() will automatically use the same Chromote.
This is so that it doesn't start a new browser for every ChromoteSession
object that is created.
Public fields
default_timeoutDefault timeout in seconds for chromote to wait for a Chrome DevTools Protocol response.
protocolDynamic protocol implementation. For expert use only!
Methods
Public methods
Method new()
Usage
Chromote$new(browser = Chrome$new(), multi_session = TRUE, auto_events = TRUE)
Arguments
browserA
Browserobjectmulti_sessionShould multiple sessions be allowed?
auto_eventsIf
TRUE, enable automatic event enabling/disabling; ifFALSE, disable automatic event enabling/disabling.
Method connect()
Re-connect the websocket to the browser. The Chrome browser automatically closes websockets when your computer goes to sleep; you can use this to bring it back to life with a new connection.
Usage
Chromote$connect(multi_session = TRUE, wait_ = TRUE)
Arguments
multi_sessionShould multiple sessions be allowed?
wait_If
FALSE, return a promise; ifTRUEwait until connection is complete.
Method view()
Display the current session in the browser
If a Chrome browser is being used, this method will open a new tab
using your Chrome browser. When not using a Chrome browser, set
options(browser=) to change the default behavior of browseURL().
Usage
Chromote$view()
Method get_auto_events()
auto_events value.
For internal use only.
Usage
Chromote$get_auto_events()
Method get_child_loop()
Local later loop.
For expert async usage only.
Usage
Chromote$get_child_loop()
Method wait_for()
Wait until the promise resolves
Blocks the R session until the promise (p) is resolved. The loop from
$get_child_loop() will only advance just far enough for the promise to
resolve.
Usage
Chromote$wait_for(p)
Arguments
pA promise to resolve.
Method new_session()
Create a new tab / window
Usage
Chromote$new_session(width = 992, height = 1323, targetId = NULL, wait_ = TRUE)
Arguments
width, heightWidth and height of the new window.
targetIdTarget ID of an existing target to attach to. When a
targetIdis provided, thewidthandheightarguments are ignored. If NULL (the default) a new target is created and attached to, and thewidthandheightarguments determine its viewport size.wait_If
FALSE, return apromises::promise()of a newChromoteSessionobject. Otherwise, block during initialization, and return aChromoteSessionobject directly.
Method get_sessions()
Retrieve all ChromoteSession objects
Usage
Chromote$get_sessions()
Returns
A list of ChromoteSession objects
Method register_session()
Register ChromoteSession object
Usage
Chromote$register_session(session)
Arguments
sessionA
ChromoteSessionobjectFor internal use only.
Method send_command()
Send command through Chrome DevTools Protocol.
For expert use only.
Usage
Chromote$send_command( msg, callback = NULL, error = NULL, timeout = NULL, sessionId = NULL )
Arguments
msgA JSON-serializable list containing
method, andparams.callbackMethod to run when the command finishes successfully.
errorMethod to run if an error occurs.
timeoutNumber of milliseconds for Chrome DevTools Protocol execute a method.
sessionIdDetermines which
ChromoteSessionwith the corresponding to send the command to.
Method invoke_event_callbacks()
Immediately call all event callback methods.
For internal use only.
Usage
Chromote$invoke_event_callbacks(event, params)
Arguments
eventA single event string
paramsA list of parameters to pass to the event callback methods.
Method debug_messages()
Enable or disable message debugging
If enabled, R will print out the
Usage
Chromote$debug_messages(value = NULL)
Arguments
valueIf
TRUE, enable debugging. IfFALSE, disable debugging.
Method debug_log()
Submit debug log message
Examples
b <- ChromoteSession$new()
b$parent$debug_messages(TRUE)
b$Page$navigate("https://www.r-project.org/")
#> SEND {"method":"Page.navigate","params":{"url":"https://www.r-project.org/"}| __truncated__}
# Turn off debug messages
b$parent$debug_messages(FALSE)
Usage
Chromote$debug_log(...)
Arguments
...Arguments pasted together with
paste0(..., collapse = "").
Method url()
Create url for a given path
Usage
Chromote$url(path = NULL)
Arguments
pathA path string to append to the host and port
Method is_active()
Is there an active websocket connection to the browser process?
Usage
Chromote$is_active()
Method is_alive()
Is the underlying browser process running?
Usage
Chromote$is_alive()
Method check_active()
Check that a chromote instance is active and alive. Will automatically reconnect if browser process is alive, but there's no active web socket connection.
Usage
Chromote$check_active()
Method get_browser()
Retrieve Browser' object
Usage
Chromote$get_browser()
Method close()
Close the Browser object
Usage
Chromote$close()
Method print()
Summarise the current state of the object.
Usage
Chromote$print(..., verbose = FALSE)
Arguments
...Passed on to
format()whenverbose= TRUEverboseThe print method defaults to a brief summary of the most important debugging info; use
verbose = TRUEtp see the complex R6 object.