Closed juba closed 5 years ago
It is not really document properly but there is an example on how it works in the README
library(promises)
library(crrri)
library(jsonlite)
chrome <- chr_connect()
chrome %>% # await R connexion to headless Chrome
Page.enable() %>% # await enablement of the Page domain
Page.navigate(url = "https://www.r-project.org/") %>% # await navigation starts
Page.frameStoppedLoading(frameId = ~ .res$frameId) %>% # await the event "Page.frameStoppedLoading"
Page.printToPDF() %...T>% { # await PDF reception
.$result$data %>% base64_dec() %>% writeBin("r_project.pdf")
} %>%
finally(~ chr_disconnect(chrome)) %...!% { # disconnect and close Chrome
cat(c("An error has occured:\n", .$message, "\n")) # handle errors
}
In this example, you have one event listened
Page.frameStoppedLoading(frameId = ~ .res$frameId)
If you understand correctly that in chrome devtools protocol event have not argument but chrome sent a message with those values, in crrri
we use those values as parameter so that you can filter which event to wait for.
Here, in the example, we listen to an event Page.frameStoppedLoading
sent by chrome, but a specific event where frameId
param sent by chrome with the event correspond to the frameId
sent back by the Page.navigate
method. (hope it is clear)
So, the elements are considered as argument by crrri
function because you can filtered an event based on each of its returned value so that you wait for the correct event.
We may need to explain that more clearly in a vignette and more examples 🤔
Ah, thanks for the explanation. I didn't understand this at first but I didn't take the time to read DevTools protocol documentation either. That makes sense now, even if maybe it could be useful to specify it in the man pages, as it is a really interesting feature.
@juba I will close this for now as we are rewriting the API and documentation will change (and it has disapeared). We can reopen this one or another issue later depending on how our documentation will evolve. Thanks !
Hi,
When I look at the man page of a function of type "Event", such as
Network.requestIntercepted
, it seems to me that the elements described in Arguments are in fact the elements returned as Values. In this case, for example, theinterceptionId
element is returned after the event is fired, but it is not an argument ofNetwork.requestIntercepted
.It's possible I'm completely misunderstanding, my apologies if this is the case.