pub struct CdpClient { /* private fields */ }Expand description
Chrome DevTools Protocol client.
Connects to a browser via WebSocket and provides access to CDP commands and events.
let cdp = cdp_use::CdpClient::connect("ws://127.0.0.1:9222/devtools/browser/...").await?;
let result = cdp.send_raw("Target.getTargets", serde_json::json!({}), None).await?;
cdp.close().await?;Implementations§
Source§impl CdpClient
impl CdpClient
Sourcepub async fn connect(url: &str) -> Result<Self, CdpError>
pub async fn connect(url: &str) -> Result<Self, CdpError>
Connect to a CDP endpoint via WebSocket with default configuration.
Sourcepub async fn connect_with_config(
url: &str,
config: CdpClientConfig,
) -> Result<Self, CdpError>
pub async fn connect_with_config( url: &str, config: CdpClientConfig, ) -> Result<Self, CdpError>
Connect to a CDP endpoint via WebSocket with custom configuration.
use cdp_use::{CdpClient, CdpClientConfig};
use std::time::Duration;
let config = CdpClientConfig {
command_timeout: Duration::from_secs(60),
..Default::default()
};
let cdp = CdpClient::connect_with_config("ws://127.0.0.1:9222/devtools/browser/...", config).await?;Sourcepub async fn send_raw(
&self,
method: &str,
params: Value,
session_id: Option<&str>,
) -> Result<Value, CdpError>
pub async fn send_raw( &self, method: &str, params: Value, session_id: Option<&str>, ) -> Result<Value, CdpError>
Send a raw CDP command and await the response.
Returns CdpError::ConnectionClosed if the connection is already closed,
or CdpError::Timeout if the browser does not respond within the timeout.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CdpClient
impl !RefUnwindSafe for CdpClient
impl Send for CdpClient
impl Sync for CdpClient
impl Unpin for CdpClient
impl UnsafeUnpin for CdpClient
impl !UnwindSafe for CdpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more