Chromote | R Documentation |
Chromote class
Chromote class
This class represents the browser as a whole.
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.
default_timeout
Default timeout in seconds for chromote to wait for a Chrome DevTools Protocol response.
protocol
Dynamic protocol implementation. For expert use only!
new()
Chromote$new(browser = Chrome$new(), multi_session = TRUE, auto_events = TRUE)
browser
A Browser
object
multi_session
Should multiple sessions be allowed?
auto_events
If TRUE
, enable automatic event enabling/disabling;
if FALSE
, disable automatic event enabling/disabling.
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()
.
Chromote$view()
get_auto_events()
auto_events
value.
For internal use only.
Chromote$get_auto_events()
get_child_loop()
Local later loop.
For expert async usage only.
Chromote$get_child_loop()
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.
Chromote$wait_for(p)
p
A promise to resolve.
new_session()
Create a new tab / window
Chromote$new_session(width = 992, height = 1323, targetId = NULL, wait_ = TRUE)
width, height
Width and height of the new window.
targetId
Target
ID of an existing target to attach to. When a targetId
is provided, the
width
and height
arguments are ignored. If NULL (the default) a new
target is created and attached to, and the width
and height
arguments determine its viewport size.
wait_
If FALSE
, return a promises::promise()
of a new
ChromoteSession
object. Otherwise, block during initialization, and
return a ChromoteSession
object directly.
get_sessions()
Retrieve all ChromoteSession
objects
Chromote$get_sessions()
A list of ChromoteSession
objects
register_session()
Register ChromoteSession
object
Chromote$register_session(session)
session
A ChromoteSession
object
For internal use only.
send_command()
Send command through Chrome DevTools Protocol.
For expert use only.
Chromote$send_command( msg, callback = NULL, error = NULL, timeout = NULL, sessionId = NULL )
msg
A JSON-serializable list containing method
, and params
.
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.
invoke_event_callbacks()
Immediately call all event callback methods.
For internal use only.
Chromote$invoke_event_callbacks(event, params)
event
A single event string
params
A list of parameters to pass to the event callback methods.
debug_messages()
Enable or disable message debugging
If enabled, R will print out the
Chromote$debug_messages(value = NULL)
value
If TRUE
, enable debugging. If FALSE
, disable debugging.
debug_log()
Submit debug log message
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)
Chromote$debug_log(...)
...
Arguments pasted together with paste0(..., collapse = "")
.
url()
Create url for a given path
Chromote$url(path = NULL)
path
A path string to append to the host and port
is_active()
Retrieve active status
Once initialized, the value returned is TRUE
. If $close()
has been
called, this value will be FALSE
.
Chromote$is_active()
get_browser()
Retrieve Browser
' object
Chromote$get_browser()
close()
Close the Browser
object
Chromote$close()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.