Comments (6)
Ok so we are in sync. 🎉
I digged into puppeteer back in december when I worked on the first version of eventemitter and CDPSession, so I exactly see your point and I share this 100%.
This is also close to the idea (I can't find where I put it...) of registering known event from the protocol, as in puppeteer.
We should then bring to live our other 📦 idea to begin filling this in there. This issue belongs there.
from crrri.
Example :
library(promises)
library(crrri)
chrome <- Chrome$new("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless = FALSE)
plop <- "<h1> pouet </h1>"
tmp <- tempfile(fileext = ".html")
write(plop, tmp)
chrome$connect() %...>%
(function(client) {
Page <- client$Page
#browser()
Page$enable() %...>% { # await enablement of the Page domain
Page$navigate(url = sprintf("file://%s", tmp) )
Page$loadEventFired() # await the load event
} %...>% {
client
}
}) %...!% {
# handle errors
cat("An error has occured:", .$message, "\n")
}
from crrri.
Nice idea for a helper function !
@RLesur This keeps on bringing the question of this kind of function being inside this 📦 or in the other one (still in conception in-our-mind though...).
What still bother me is that I think that crrri should only have methods related to chrome remote interface or only internal helpers and that any other methods seen as user's helpers should live in another object completing the one in crrri.
This mean I don't think adding a navigateToFile
inside Page Domain R6 object makes sense here as it is not a method of the Page Domain from the protocol. All the more because we generate the Domain method directly from the protocol. Do you share this thought ?
However, we may be able to find how to add those in a way that makes it clear in the code (for us and other) what is from the Page domain and what is not (i.e completing it).
No matter what we decide here, we should consider, now the API is more stable, how and where we start adding such helper.
What are your thoughts on that ?
from crrri.
My views are the following:
crrri
should be close to the protocol- we should not modify domains. The main reason is that the protocol is retrieved by default from the remote Chrome
crrri
is designed to be reused
In order to provide an example, here is a sketch of the puppeteer's page.goto()
method
First, the user's view (I think this is very close to @ColinFay's proposal):
chrome <- Chrome$new()
plop <- "<h1> pouet </h1>"
tmp <- tempfile(fileext = ".html")
write(plop, tmp)
client <- marionette(chrome)
client %...>% (function(client) {
page <- client$page
page$goto(tmp)
})
# confirm that we got a beautiful Pouet in Chrome
chrome$view()
Now, the whole script. I've adopted here the same structure as in crrri
:
library(crrri)
# Domains for Marionette
MarionetteDomain <- R6::R6Class(
"MarionetteDomain",
public = list(
initialize = function(marionette) {
private$.marionette <- marionette
}
),
private = list(
.marionette = NULL
)
)
# page domain (as in puppeteer)
page <- R6::R6Class(
"page",
inherit = MarionetteDomain,
public = list(
# see puppeteer page.goto method
goto = function(url, waitUntil = c("load", "domcontentloaded"), timeout = 30) {
url <- httr::parse_url(url)
if(is.null(url$scheme)) {
url$scheme <- "file"
}
url <- httr::build_url(url)
Page <- private$.marionette$.__client__$Page
waitUntil <- match.arg(waitUntil)
ready <- switch(waitUntil,
load = Page$loadEventFired(),
domcontentloaded = Page$domContentEventFired())
Page$enable() %...>% {
Page$navigate(url = url)
ready
} %>%
timeout(timeout)
}
)
)
# Marionette R6 class
Marionette <- R6::R6Class(
"Marionette",
public = list(
initialize = function(client) {
self$.__client__ <- client
self$page <- page$new(self)
},
page = NULL,
disconnect = function() {
self$.__client__$disconnect()
},
.__client__ = NULL
)
)
# use a constructor
marionette <- function(chrome) {
chrome$connect() %...>% (function(client) {
Marionette$new(client)
})
}
# let's play with marionette
chrome <- Chrome$new()
plop <- "<h1> pouet </h1>"
tmp <- tempfile(fileext = ".html")
write(plop, tmp)
client <- marionette(chrome)
client %...>% (function(client) {
page <- client$page
page$goto(tmp)
})
# confirm that we got a beautiful Pouet in Chrome
chrome$view()
from crrri.
@RLesur how to do we proceed on this one ? Should we create another recipes package ?
@ColinFay is this idea of yours part of your project 📦 for shiny helpers based on crrri ?
from crrri.
I still think that recipes should be in another package. I have no time yet to initiate it, do not hesitate to start!
from crrri.
Related Issues (20)
- Logic for returning results from a function that get XHR calls response body HOT 3
- How to send some value to web page and get the output saved or retrieved as dataframe HOT 12
- Can't create chromium instance on debian linux 10 HOT 1
- chrome_read_html HOT 6
- Run in Github Actions HOT 4
- Is possible to extract data from Power BI dashboard using crrri package?
- Select Dropdown not working
- Upload File HOT 1
- Cannot open URL 'http://localhost:9222/json/new': HTTP status was '405 Method Not Allowed' HOT 4
- websites that don't like to be scraped HOT 1
- Document R6 class using new roxygen feature HOT 5
- Finalize a stable version ? HOT 1
- Add support and document about New Edge Chromium HOT 1
- Allow to load user profile in non-headless mode HOT 8
- add some more default flags to launch chromium
- Allow children to close parent connection HOT 2
- Suggestion: automatically find a free port if the specified is not. HOT 2
- Purge crrrri cache HOT 1
- switch CI to Github Actions HOT 2
- R 4.0.0 now runs donttest example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crrri.