Coder Social home page Coder Social logo

Comments (15)

stevepryde avatar stevepryde commented on July 2, 2024 3

For anyone else looking for CDP support, start here: https://docs.rs/thirtyfour/latest/thirtyfour/extensions/cdp/struct.ChromeDevTools.html

CDP itself is quite large, so we may not have high-level wrappers around it in the short term, but you can implement it yourself without needing to modify thirtyfour.
CDP docs are here: https://chromedevtools.github.io/devtools-protocol/

from thirtyfour.

stevepryde avatar stevepryde commented on July 2, 2024 1

I don't think this is possible in thirtyfour currently. Would you be willing to contribute this feature?

from thirtyfour.

DCjanus avatar DCjanus commented on July 2, 2024 1

Sounds good to me.

from thirtyfour.

notdanilo avatar notdanilo commented on July 2, 2024 1

I just found this link, which describes the protocol process pretty well: https://github.com/aslushnikov/getting-started-with-cdp

from thirtyfour.

DCjanus avatar DCjanus commented on July 2, 2024

I am not very familiar with chrome driver special protocol, like /session/{session_id}/goog/cdp/execute, is there any place that I can find it,

from thirtyfour.

stevepryde avatar stevepryde commented on July 2, 2024

Have a look here: https://chromedevtools.github.io/devtools-protocol/

Edit: use the navigation on the side to view docs for each command

from thirtyfour.

stevepryde avatar stevepryde commented on July 2, 2024

You can also check out other selenium libraries such as the python one to see how they do it

from thirtyfour.

DCjanus avatar DCjanus commented on July 2, 2024

It looks like that selenium open a websocket connection to accept CDP event, which means we need to introduce a websocket library to thirtyfour.

Which websocket library would you like to use?

I'm not familiar with this domain, my friends told me tokio-tungstenite is the best chose, but it doesn't support async-std, and there is a fork to support different async runtime.

from thirtyfour.

stevepryde avatar stevepryde commented on July 2, 2024

Yeah have a look at https://github.com/sdroege/async-tungstenite which supports both runtimes via feature flags

Edit: just realised that's the one you linked to 😂

from thirtyfour.

audioXD avatar audioXD commented on July 2, 2024

I thought that most libraries just use a proxy to intercept all those requests :p

from thirtyfour.

stevepryde avatar stevepryde commented on July 2, 2024

You can use a proxy, however you can use CDP to do it, which I would prefer over a proxy since it's coming from the browser itself. It's more like listening to the browser's network tab

from thirtyfour.

notdanilo avatar notdanilo commented on July 2, 2024

Any success on listening the events from a websocket connection? I am trying this with no success yet:

    let response = reqwest::get("http://localhost:9222/json/version")
        .await?
        .json::<HashMap<String, String>>()
        .await?;
    let ws_debugger_url = response.get("webSocketDebuggerUrl").expect("Couldn't get ws debugger url.");

    let (mut socket, _) = connect_async(Url::parse(ws_debugger_url)?).await?;
    
        let dev_tools = ChromeDevTools::new(driver.session());
    let version_info = dev_tools.execute_cdp("Browser.getVersion").await?;
    println!("{:#?}", version_info);

    std::thread::sleep(Duration::from_secs_f64(3.0));
    println!("{:#?}", dev_tools.execute_cdp("HeapProfiler.enable").await?);
    println!("{:#?}", dev_tools.execute_cdp_with_params("HeapProfiler.takeHeapSnapshot", json!({"reportProgress":true,"treatGlobalObjectsAsRoots":true,"captureNumericValue":false})).await?);

    while let Some(Ok(message)) = socket.next().await {
        println!("{}", message);
    }

from thirtyfour.

notdanilo avatar notdanilo commented on July 2, 2024

Maybe I am missing the session ID or something that binds the websocket to the client sending the requests?

from thirtyfour.

audioXD avatar audioXD commented on July 2, 2024

@notdanilo I saw that the OP made a project seperate from thirtyfour, chromiumoxide made for CDP. To be honest it looks quite similar (but works only for chrome)

EDIT: Yust realized it was a fork from @mattsse

from thirtyfour.

notdanilo avatar notdanilo commented on July 2, 2024

@audioXD I urgently created a CDP client myself because I couldn't get chromiumoxide working. The reason it didnt work was because I was simply misunderstanding how the protocol works and chromiumoxide didn't provide a high level API for what I wanted (getting a memory heap snapshot).

I am still using thirtyfour for collecting information from html although.

from thirtyfour.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.