javascriptrphantomjschromote

Is it possible to include a JavaScript library with chromote?


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.


Solution

  • 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)