Skip to main content

CdpClient

Struct CdpClient 

Source
pub struct CdpClient { /* private fields */ }
Expand description

A multiplexed connection to Chrome DevTools Protocol.

The connection task owns the WebSocket and the pending request map. This keeps response routing and event delivery in one place while allowing multiple commands to be in flight at once.

Implementations§

Source§

impl CdpClient

Source

pub fn request_count(&self) -> u64

Number of CDP requests allocated by this connection so far.

This is a monotonic diagnostic counter and does not retain request payloads or alter command routing.

Source

pub fn cdp_wait_nanos(&self) -> u64

Total time spent awaiting CDP responses on this connection.

This is a monotonic diagnostic counter used by the benchmark to separate protocol wait time from Glass-side orchestration work.

Source

pub async fn measure_cdp_wait<F>(&self, future: F) -> (F::Output, u64)
where F: Future,

Measure CDP response wait time initiated by one async operation.

The scope is task-local, so detached cleanup work does not get charged to the operation that caused it.

Source

pub async fn connect(ws_url: &str) -> Result<Self, Box<dyn Error>>

Connect to a Chrome CDP page WebSocket using the default timeout.

Source

pub async fn connect_with_timeout( ws_url: &str, timeout: Duration, ) -> Result<Self, Box<dyn Error>>

Connect to a Chrome CDP page WebSocket with a custom command timeout.

Source

pub fn subscribe_events(&self) -> Receiver<CdpEvent>

Subscribe to method-only CDP events such as page lifecycle events.

Source

pub fn subscribe_events_with_params(&self) -> Receiver<CdpEventWithParams>

Subscribe to CDP events with payloads for explicit media or diagnostic work.

Payload JSON is parsed only while this stream has at least one receiver.

Source

pub fn open_screencast_channel( &self, session_id: Option<String>, ) -> Result<Receiver<CdpScreencastFrame>, CdpError>

Source

pub fn close_screencast_channel(&self) -> (u64, u64)

Source

pub fn screencast_stats(&self) -> (u64, u64)

Source

pub fn current_session_id(&self) -> Option<String>

Source

pub async fn set_domain_enabled_for( &self, session_id: Option<String>, domain: &str, enabled: bool, ) -> Result<(), CdpError>

Source

pub async fn send( &self, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>

Send a CDP command and wait for the response.

Source

pub async fn send_typed<R: DeserializeOwned>( &self, method: &str, params: Option<Value>, ) -> Result<R, CdpError>

Send a command and deserialize its response into a caller-owned type.

The untyped send method remains available at the CDP boundary, while session code can use this helper for stable response shapes without repeatedly indexing raw serde_json::Value objects.

Source

pub async fn send_browser_typed<R: DeserializeOwned>( &self, method: &str, params: Option<Value>, ) -> Result<R, CdpError>

Typed variant of send_browser.

Source

pub async fn send_to_session_typed<R: DeserializeOwned>( &self, session_id: &str, method: &str, params: Option<Value>, ) -> Result<R, CdpError>

Typed variant of send_to_session.

Source

pub async fn send_browser( &self, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>

Source

pub async fn send_to_session( &self, session_id: &str, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>

Source

pub async fn send_with_timeout( &self, method: &str, params: Option<Value>, timeout: Duration, ) -> Result<Value, CdpError>

Send one operation-scoped command without changing the connection’s default response deadline or active route.

Source

pub fn set_active_session(&self, session_id: Option<String>)

Source

pub fn set_active_context(&self, context_id: Option<i64>)

Source

pub fn set_active_frame_context( &self, frame_id: Option<String>, context_id: Option<i64>, )

Source

pub fn set_active_route( &self, session_id: Option<String>, frame_id: Option<String>, context_id: Option<i64>, )

Source

pub fn set_active_target_route( &self, target_id: Option<String>, session_id: Option<String>, frame_id: Option<String>, context_id: Option<i64>, )

Source

pub fn operation_identity(&self) -> Option<(String, String)>

Source

pub fn set_active_frame(&self, frame_id: Option<String>)

Source

pub fn active_frame(&self) -> Option<String>

Source

pub async fn with_current_route<F: Future>(&self, future: F) -> F::Output

Source

pub async fn with_current_target_route<F: Future>(&self, future: F) -> F::Output

Source

pub async fn frame_viewport_offset( &self, frame_id: &str, ) -> Result<(f64, f64), CdpError>

Return the selected child frame viewport origin in target coordinates.

Source

pub async fn navigate(&self, url: &str) -> Result<Value, CdpError>

Navigate to a URL.

Source

pub async fn screenshot(&self, format: &str) -> Result<String, CdpError>

Take a screenshot and return its base64-encoded image data.

Source

pub async fn screenshot_with_params( &self, params: Value, ) -> Result<String, CdpError>

Source

pub async fn get_layout_metrics(&self) -> Result<Value, CdpError>

Source

pub async fn get_accessibility_tree(&self) -> Result<Value, CdpError>

Get the accessibility tree.

Source

pub async fn get_flattened_document( &self, depth: i64, ) -> Result<Value, CdpError>

Get a flattened document tree including shadow DOM content. Uses pierce: true to include open shadow roots up to the given depth.

Source

pub async fn get_deep_document(&self) -> Result<Value, CdpError>

Get the full document tree for an explicit deep-DOM inspection.

Source

pub async fn get_document_root(&self) -> Result<Value, CdpError>

Get only the document root for operations that do not need descendants.

Source

pub async fn get_document(&self) -> Result<Value, CdpError>

Compatibility alias for the explicit deep-DOM request.

Source

pub async fn query_selector(&self, selector: &str) -> Result<Value, CdpError>

Query a CSS selector and return the matching node.

Source

pub async fn resolve_node_object( &self, node_id: Option<i64>, backend_node_id: Option<i64>, ) -> Result<String, CdpError>

Resolve a DOM/backend node to a reusable remote object.

Source

pub async fn backend_node_id_for_node( &self, node_id: i64, ) -> Result<i64, CdpError>

Translate one already-resolved frontend node into its immutable backend identity without repeating the caller’s locator query.

Source

pub async fn call_on_object( &self, object_id: &str, function_declaration: &str, ) -> Result<Value, CdpError>

Invoke a function on a previously resolved remote object.

Source

pub async fn release_object(&self, object_id: &str) -> Result<Value, CdpError>

Source

pub async fn release_object_for_session( &self, session_id: &str, object_id: &str, ) -> Result<Value, CdpError>

Source

pub async fn bounded_element_query( &self, expression: &str, limit: usize, ) -> Result<(usize, Vec<i64>), CdpError>

Resolve a page-produced, bounded remote element array into DOM node IDs.

The expression must return an Array with at most limit elements and a numeric glassCount property containing the total logical match count.

Source

pub async fn get_box_model(&self, node_id: i64) -> Result<Value, CdpError>

Get the bounding box of a DOM node.

Source

pub async fn get_box_model_for_backend( &self, backend_node_id: i64, ) -> Result<Value, CdpError>

Get the bounding box of a backend DOM node from an accessibility tree.

Source

pub async fn scroll_into_view_if_needed( &self, node_id: Option<i64>, backend_node_id: Option<i64>, ) -> Result<Value, CdpError>

Ask Chrome to scroll a DOM node into view only when it is necessary.

The browser owns the visibility decision, avoiding a separate layout probe and avoiding a scroll when the target is already actionable.

Source

pub async fn evaluate(&self, expression: &str) -> Result<Value, CdpError>

Evaluate JavaScript in the page.

Source

pub async fn evaluate_in_context( &self, expression: &str, context_id: Option<i64>, ) -> Result<Value, CdpError>

Source

pub async fn insert_text(&self, text: &str) -> Result<Value, CdpError>

Insert text into the currently focused element.

Source

pub async fn dispatch_mouse_event( &self, event_type: &str, x: f64, y: f64, button: Option<&str>, click_count: Option<u32>, ) -> Result<Value, CdpError>

Dispatch a mouse event via CDP Input.

Source

pub async fn dispatch_mouse_event_with_timeout( &self, event_type: &str, x: f64, y: f64, button: Option<&str>, click_count: Option<u32>, timeout: Duration, ) -> Result<Value, CdpError>

Dispatch one mouse event with a caller-owned response window.

This does not alter the connection default used by ordinary input.

Source

pub async fn dispatch_key_event( &self, event_type: &str, key: &str, code: &str, ) -> Result<Value, CdpError>

Dispatch a keyboard event via CDP Input.

Source

pub async fn dispatch_key_event_with_modifiers( &self, event_type: &str, key: &str, code: &str, text: &str, modifiers: i64, ) -> Result<Value, CdpError>

Source

pub async fn dispatch_select_all(&self) -> Result<Value, CdpError>

Invoke Blink’s platform-independent editing command on the focused node.

Source

pub async fn set_file_input_files( &self, node_id: Option<i64>, backend_node_id: Option<i64>, files: &[String], ) -> Result<Value, CdpError>

Source

pub async fn scroll_by(&self, dx: f64, dy: f64) -> Result<Value, CdpError>

Scroll the current page by a delta in CSS pixels.

Source

pub async fn get_cookies(&self) -> Result<Value, CdpError>

Source

pub async fn set_cookies(&self, cookies: Value) -> Result<Value, CdpError>

Source

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

Source

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

Source

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

Enable the only event domains required to wait for navigation and invalidate compact observations.

Source

pub async fn enable_observation_events_for( &self, session_id: &str, ) -> Result<(), CdpError>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub async fn handle_javascript_dialog( &self, accept: bool, ) -> Result<Value, CdpError>

Source

pub async fn set_download_behavior( &self, behavior: &str, download_path: Option<&Path>, events_enabled: bool, ) -> Result<Value, CdpError>

Source

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

Source

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

Source

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

Ask an owned Chrome browser to close itself before process-level shutdown. This gives profile-backed state a chance to flush cleanly.

Source

pub async fn set_device_metrics_override( &self, width: i64, height: i64, device_scale_factor: f64, mobile: bool, ) -> Result<Value, CdpError>

Override device metrics for viewport emulation.

Source

pub async fn clear_device_metrics_override(&self) -> Result<Value, CdpError>

Clear device metrics override.

Source

pub async fn close(&self)

Ask the connection task to close its WebSocket.

Trait Implementations§

Source§

impl Clone for CdpClient

Source§

fn clone(&self) -> CdpClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more