Comments (6)
Idea: with event emitter API, it would be possible to register some callback for event known as error, like Network.loadingFailed
. This way, if this message is received from chrome, we know that something went wrong and we could throw an error or a warning.
from crrri.
After 1 and 2, we have something that look like this:
- Create the connexion to the page directly.
CDPSession
class will create a websocket connection that will listen to chrome message and- emits an error events in case of a message received with an error
- emits the name of the command sent when it received a message that correspond to the good reception of a command (a message with no error and an id)
- emits the name of the method received for a message that contains a method.
These are the three types of message that we can receive from chrome.
- Defines every action in chaining using events, based on the previous emission explained above.
- send the first command to start the all flow.
devtools::load_all()
work_dir <- chr_new_data_dir()
chrome <- chr_launch(work_dir = work_dir, headless = TRUE)
ws_endpoint <- chr_get_ws_addr(debug_port = 9222, type = 'page')
# connexion to the session using page endpoint
page_session <- CDPSession$new(ws_endpoint)
page_session$once("Runtime.executionContextCreated", function(...) cat("First command passed!"))
page_session$once("Runtime.enable",
~ page_session$sendCommand('Page.enable'))
page_session$once("Page.enable",
~ page_session$sendCommand('Runtime.addBinding', params = list(name = "pagedownListener")))
page_session$once("Runtime.addBinding",
~ page_session$sendCommand('Page.navigate',
params = list(url = "file:///C:/Users/chris/Documents/test.nb.html")))
page_session$once('Page.domContentEventFired',
~ page_session$sendCommand('Runtime.evaluate',
params = list(expression = "!!window.PagedPolyfill")
))
page_session$once("Runtime.evaluate",
function(data) if (!isTRUE(data$result$result$value)) {
page_session$sendCommand("Page.printToPDF",
params = list(printBackground = TRUE, preferCSSPageSize = TRUE))
})
page_session$once('Runtime.bindingCalled',
~ page_session$sendCommand("Page.printToPDF",
params = list(printBackground = TRUE, preferCSSPageSize = TRUE)
))
page_session$once("Page.printToPDF",
function(data) writeBin(jsonlite::base64_dec(data$result$data), "test.pdf"))
# will launch all the registered events in sequence
page_session$sendCommand('Runtime.enable')
from crrri.
Following a discussion on slack, it seems possible to offer several working APIs if we organize things correctly by stage:
- eventEmitter
- callbacks
- promises (modifié)
This seems like a very good idea.
from crrri.
This has been going well with #38 and #35. This issue needs to be split in several ideas that we still want to implement and be closed.
from crrri.
This is now handle in #40 and will be closed by the merge I think. Are we ok on this ?
from crrri.
Sounds good to me
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
- Allow to pass non integer number as port HOT 2
- 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.