The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Attaching to existing tabs

library(chromote)
r <- Chromote$new()

When you use ChromoteSession$new() or b$new_session(), you’re typically connecting to an existing browser, but creating a new tab to attach to. It’s also possible to attach to an existing browser and and existing tab. In Chrome debugging terminology a tab is called a “Target”, and there is a command to retrieve the list of current Targets:

r$Target$getTargets()

Every target has a unique identifier string associated with it called the targetId; "9DAE349A3A533718ED9E17441BA5159B" is an example of one.

Here we define a function that retrieves the ID of the first Target (tab) from a Chromote object:

first_id <- function(r) {
  ts <- r$Target$getTargets()$targetInfos
  stopifnot(length(ts) > 0)
  r$Target$getTargets()$targetInfos[[1]]$targetId
}

The following code shows an alert box in the first tab, whatever it is:

rc <- ChromeRemote$new(host = "localhost", port = 9222)
r <- Chromote$new(browser = rc)
tid <- first_id(r)
b <- r$new_session(targetId = tid)
b$Runtime$evaluate('alert("this is the first tab")')

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.