可以在chromote中包含JavaScript库吗?

huangapple go评论63阅读模式
英文:

Is it possible to include a JavaScript library with chromote?

问题

使用 phantomJS 可以通过 page.inject("thelibrary.js") 来包含一个 JavaScript 库。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.

答案1

得分: 0

      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)
英文:

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)

huangapple
  • 本文由 发表于 2023年6月29日 20:13:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580945.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定