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_timeout
Default timeout in seconds for chromote to wait for a Chrome DevTools Protocol response.
protocol
Dynamic protocol implementation. For expert use only!
Methods
Method new()
Arguments
browser
A
Browser
objectmulti_session
Should multiple sessions be allowed?
auto_events
If
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.
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()
.
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.
Method new_session()
Create a new tab / window
Arguments
width, height
Width and height of the new window.
targetId
Target ID of an existing target to attach to. When a
targetId
is provided, thewidth
andheight
arguments are ignored. If NULL (the default) a new target is created and attached to, and thewidth
andheight
arguments determine its viewport size.wait_
If
FALSE
, return apromises::promise()
of a newChromoteSession
object. Otherwise, block during initialization, and return aChromoteSession
object directly.
Method get_sessions()
Retrieve all ChromoteSession
objects
Method register_session()
Register ChromoteSession
object
Method send_command()
Send command through Chrome DevTools Protocol.
For expert use only.
Arguments
msg
A JSON-serializable list containing
method
, andparams
.callback
Method to run when the command finishes successfully.
error
Method to run if an error occurs.
timeout
Number of milliseconds for Chrome DevTools Protocol execute a method.
sessionId
Determines which
ChromoteSession
with the corresponding to send the command to.
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)
Method url()
Create url for a given path
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.