Is it possible to include a JavaScript library with chromote?

66 Views Asked by At

With phantomJS one can include a JavaScript library by doing page.inject("thelibrary.js"). Is it possible with the chromote package? I didn't find anything in the doc.

1

There are 1 best solutions below

0
On BEST ANSWER

One can do

      chrm <- Chrome$new(
        path = chromePath,
        args = "--disable-gpu --headless --remote-debugging-port=9222"
      )
      chromote <- Chromote$new(browser = chrm)
      session  <- ChromoteSession$new(parent = chromote)
      ids <- session$Page$navigate("about:blank")
      jsfile <- "path/to/jslibrary"
      library <- paste0(readLines(jsfile), collapse = "\n")
      . <- session$Runtime$evaluate(library)