pub mod browser;
pub mod dom;
pub mod fetch;
pub mod input;
pub mod network;
pub mod oxi;
pub mod page;
pub mod runtime;
pub mod target;
use crate::event::EventSender;
use crate::protocol::CdpError;
use oxibrowser_core::network::SharedRegistry;
use oxibrowser_core::session::Session;
use serde_json::Value;
use std::sync::Arc;
use tokio::sync::RwLock;
pub struct DispatchContext {
pub session: Arc<RwLock<Session>>,
pub events: EventSender,
pub fetch_registry: SharedRegistry,
}
pub type DomainResult = std::result::Result<Option<Value>, CdpError>;
pub async fn dispatch(method: &str, params: Option<Value>, ctx: &DispatchContext) -> DomainResult {
let parts: Vec<&str> = method.splitn(2, '.').collect();
if parts.len() != 2 {
return Err(CdpError {
code: -32601,
message: format!("invalid method: {method}"),
});
}
let (domain, method_name) = (parts[0], parts[1]);
match domain {
"Browser" => browser::handle(method_name, params),
"DOM" => dom::handle(method_name, params, ctx).await,
"Fetch" => fetch::handle(method_name, params, ctx).await,
"Network" => network::handle(method_name, params, ctx).await,
"OXI" => oxi::handle(method_name, params, ctx).await,
"Input" => input::handle(method_name, params, ctx).await,
"Page" => page::handle(method_name, params, ctx).await,
"Runtime" => runtime::handle(method_name, params, ctx).await,
"Target" => target::handle(method_name, params, ctx),
_ => Err(CdpError {
code: -32601,
message: format!("unknown domain: {domain}"),
}),
}
}