You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to connect to a node.js process which is setup with --inspect and listening on 9229. I'm able to connect, enable runtime, etc. However, what I can't do is get any of the events for the inspect to come through chromiumoxide. They are being sent over the wire just fine and I can parse them using a raw websocket client (see data below). However, chromiumoxide seems to be filtering them and never processing them as part of the even listener streams I've set up.
Any suggestions / assistance?
Test code:
use chromiumoxide::browser::Browser;use chromiumoxide::cdp::js_protocol::runtime::{EnableParams,EvaluateParams,EventConsoleApiCalled};use futures::StreamExt;use reqwest;use serde::Deserialize;use std::error::Error;use std::time::Duration;use tokio::time::sleep;#[derive(Debug,Deserialize)]structTargetInfo{#[serde(rename = "webSocketDebuggerUrl")]web_socket_debugger_url:Option<String>,}#[tokio::main]asyncfnmain() -> Result<(),Box<dynError>>{// Poll the /json/list endpoint until a target with a valid WebSocket URL is found.let json_endpoint = "http://localhost:9229/json/list";let ws_url = loop{match reqwest::get(json_endpoint).await{Ok(resp)if resp.status().is_success() => {match resp.json::<Vec<TargetInfo>>().await{Ok(targets) => {ifletSome(target) = targets.iter().find(|t| t.web_socket_debugger_url.is_some()){let url = target.web_socket_debugger_url.as_ref().unwrap().to_string();println!("Found WebSocket URL: {}", url);break url;}else{eprintln!("No target with a valid WebSocket URL found. Retrying in 1 second...");}}Err(e) => {eprintln!("Failed to parse JSON: {}. Retrying in 1 second...", e);}}}Ok(resp) => {eprintln!("Received non-success status {}. Retrying in 1 second...", resp.status());}Err(e) => {eprintln!("Failed to get target info: {}. Retrying in 1 second...", e);}}sleep(Duration::from_secs(1)).await;};// Connect to the target using the obtained WebSocket URL.let(browser,mut handler) = Browser::connect(&ws_url).await?;println!("Connected to {}", ws_url);// Spawn a background task that prints all raw CDP events from the connection.
tokio::spawn(asyncmove{whileletSome(raw_event) = handler.next().await{println!("Raw CDP event: {:?}", raw_event);}});// Optionally, enable the Runtime domain if you want to evaluate scripts.
browser.execute(EnableParams::default()).await?;// Subscribe to console API events.letmut console_events = browser.event_listener::<EventConsoleApiCalled>().await?;println!("Subscribed to Runtime.consoleAPICalled events.");// Wait briefly to ensure the event subscription is fully active.sleep(Duration::from_millis(500)).await;// Optionally, evaluate a script that triggers a console.log.let eval_script = r#" setTimeout(() => { console.log('Test message from evaluated script'); }, 100); "#;let _ = browser.execute(EvaluateParams::new(eval_script)).await?;println!("Evaluate command executed.");// Listen for both types of events.loop{
tokio::select! {Some(exec_event) = console_events.next() => {
println!("Console event: {:?}", exec_event);},
_ = sleep(Duration::from_secs(1)) => {// No events, loop and wait.},}}}
I'm trying to connect to a node.js process which is setup with --inspect and listening on 9229. I'm able to connect, enable runtime, etc. However, what I can't do is get any of the events for the inspect to come through chromiumoxide. They are being sent over the wire just fine and I can parse them using a raw websocket client (see data below). However, chromiumoxide seems to be filtering them and never processing them as part of the even listener streams I've set up.
Any suggestions / assistance?
Test code:
Over the wire:
The text was updated successfully, but these errors were encountered: