RLesur / crrri

A Chrome Remote Interface written in R
https://rlesur.github.io/crrri/
Other
157 stars 12 forks source link

Can't access `.$result$root$nodeId` from `DOM.getDocument()` #30

Closed juba closed 5 years ago

juba commented 5 years ago

The following code aims to dump the DOM of a web page :

url <- "https://www.r-project.org/"
chrome <- chr_connect(bin = "google-chrome", headless = FALSE)
gd <- chrome %>% 
  Page.enable() %>% 
  DOM.enable() %>%
  Page.navigate(url) %>% 
  Page.loadEventFired() %>%
  DOM.getDocument()

gd %>%   
  DOM.getOuterHTML(nodeId = .$result$root$nodeId)

But it fails at DOM.getOuterHTML(nodeId = .$result$root$nodeId) with Error: Invalid parameters(code -32602)

It does work when giving a nodeId directly :

gd %>%   
  DOM.getOuterHTML(nodeId = 1)

And the .$result$root$nodeId value is correct :

gd %...>% {
  print(.$result$root$nodeId)
}
RLesur commented 5 years ago

I fixed the issue. The only mean for reusing the previous result is by using a formula:

gd %>% DOM.getOuterHTML(nodeId = ~ .res$root$nodeId)

or

gd %>% DOM.getOuterHTML(nodeId = ~ .$root$nodeId)
juba commented 5 years ago

I can confirm it's fixed for me too. Thanks a lot !

cderv commented 5 years ago

For reference, I build on this example to test my search on second API based on EventEmitter without promise (see #28) https://gist.github.com/cderv/67d7ad8998559f2ce14b4eb4bb852fd1