#| echo: false if (!exists("MAN_PATH")) MAN_PATH <- "man"
This will start a headless browser and open an interactive viewer for it in a normal browser, so that you can see what the headless browser is doing.
library(chromote) b <- ChromoteSession$new() # In a web browser, open a viewer for the headless browser. Works best with # Chromium-based browsers. b$view()
The browser can be given commands, as specified by the Chrome DevTools Protocol. For example, $Browser$getVersion()
(which corresponds to the Browser.getVersion in the API docs) will query the browser for version information:
b$Browser$getVersion() #> $protocolVersion #> [1] "1.3" #> #> $product #> [1] "HeadlessChrome/98.0.4758.102" #> #> $revision #> [1] "@273bf7ac8c909cde36982d27f66f3c70846a3718" #> #> $userAgent #> [1] "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/98.0.4758.102 Safari/537.36" #> #> $jsVersion #> [1] "9.8.177.11"
If you have the viewer open and run the following, you'll see the web page load in the viewer[^interactive]:
b$go_to("https://www.r-project.org/")
In addition to full support of the Chrome Devtools Protocol, ChromoteSession
objects also have some convenience methods, like $go_to()
and $screenshot()
. (See the Examples section below for more information about screenshots.)
# Saves to screenshot.png b$screenshot() # Takes a screenshot of elements picked out by CSS selector b$screenshot("sidebar.png", selector = ".sidebar")
[^interactive]: This simple example works interactively, but if you're using chromote to programmatically take screenshots you'll want to read vignette("example-loading-page")
for a consistent and reliable approach.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.