pub struct CdpClient { /* private fields */ }Expand description
A CDP client connected to Chrome over WebSocket.
This is the main entry point for sending CDP commands and subscribing to events. It communicates with a background transport task that owns the WebSocket connection.
Implementations§
Source§impl CdpClient
impl CdpClient
Sourcepub async fn connect(url: &str, config: CdpConfig) -> Result<Self, CdpError>
pub async fn connect(url: &str, config: CdpConfig) -> Result<Self, CdpError>
Connect to a Chrome CDP WebSocket endpoint.
§Errors
Returns CdpError::Connection if the WebSocket handshake fails,
or CdpError::ConnectionTimeout if the connection attempt exceeds
the configured timeout.
Sourcepub async fn send_command(
&self,
method: &str,
params: Option<Value>,
) -> Result<Value, CdpError>
pub async fn send_command( &self, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>
Send a CDP command (browser-level, no session).
§Errors
Returns CdpError::CommandTimeout if Chrome does not respond within
the configured timeout, CdpError::Protocol if Chrome returns an
error, or CdpError::Internal if the transport task has exited.
Sourcepub async fn subscribe(
&self,
method: &str,
) -> Result<Receiver<CdpEvent>, CdpError>
pub async fn subscribe( &self, method: &str, ) -> Result<Receiver<CdpEvent>, CdpError>
Subscribe to CDP events matching a method name.
Returns a receiver that yields CdpEvent values. Events stop
being delivered when the receiver is dropped.
§Errors
Returns CdpError::Internal if the transport task has exited.
Sourcepub async fn create_session(
&self,
target_id: &str,
) -> Result<CdpSession, CdpError>
pub async fn create_session( &self, target_id: &str, ) -> Result<CdpSession, CdpError>
Create a CDP session attached to a specific target.
Sends Target.attachToTarget and returns a CdpSession bound
to the returned session ID.
§Errors
Returns CdpError::Protocol if the target cannot be attached,
or any transport error.
Sourcepub async fn close(self) -> Result<(), CdpError>
pub async fn close(self) -> Result<(), CdpError>
Gracefully close the WebSocket connection.
§Errors
Returns CdpError::Internal if the transport task has already exited.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the client is currently connected.