Skip to main content

CdpClient

Struct CdpClient 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn close(self) -> Result<(), CdpError>

Gracefully close the WebSocket connection.

§Errors

Returns CdpError::Internal if the transport task has already exited.

Source

pub fn is_connected(&self) -> bool

Check if the client is currently connected.

Source

pub fn url(&self) -> &str

Get the WebSocket URL this client is connected to.

Trait Implementations§

Source§

impl Debug for CdpClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V