Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAR file & listen for Request/Response events. #254

Open
gtokman opened this issue Jan 27, 2025 · 0 comments
Open

HAR file & listen for Request/Response events. #254

gtokman opened this issue Jan 27, 2025 · 0 comments

Comments

@gtokman
Copy link

gtokman commented Jan 27, 2025

Awesome project! Is there an easy way to add event handlers for Request & Response events?

I want to be able to track all the API calls that a website is making as I am navigating. I didn't see anything in this realm when browsing the examples. Also, I know Chrome dev tools supports exporting a HAR (HTTP archive file), is this possible?

Trying this on a example project was a bit difficult, I couldn't get the handlers to attach when a new page was created.

use std::sync::Arc;
use chromiumoxide::browser::{Browser, BrowserConfig};
use chromiumoxide::cdp::browser_protocol::{
    fetch::EventRequestPaused,
    network::EventResponseReceived,
    target::{
      AttachToTargetParams, EventTargetCreated,
    },
};
use futures::StreamExt;
  let mut request_paused = match new_page.event_listener::<EventRequestPaused>().await {
                               Ok(rp) => rp,
                                Err(e) => {
                                    eprintln!("Failed to create request_paused listener: {e}");
                                    continue;
                                }
                            };
                            async_std::task::spawn(async move {
                                while let Some(event) = request_paused.next().await {
                                    println!("--- Request Paused ---");
                                    println!("URL: {}", event.request.url);
                                    println!("Method: {}", event.request.method);
                                }
                            });
   let mut response_received = match new_page.event_listener::<EventResponseReceived>().await {
                                Ok(rr) => rr,
                                Err(e) => {
                                    eprintln!("Failed to create response_received listener: {e}");
                                    continue;
                                }
                            };
                            async_std::task::spawn(async move {
                                while let Some(event) = response_received.next().await {
                                    println!("--- Response Received ---");
                                    println!("URL: {}", event.response.url);
                                    println!("Status: {}", event.response.status);
                                }
                            });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant