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
impl CdpClient
Sourcepub fn request_count(&self) -> u64
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.
Sourcepub fn cdp_wait_nanos(&self) -> u64
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.
Sourcepub async fn measure_cdp_wait<F>(&self, future: F) -> (F::Output, u64)where
F: Future,
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.
Sourcepub async fn connect(ws_url: &str) -> Result<Self, Box<dyn Error>>
pub async fn connect(ws_url: &str) -> Result<Self, Box<dyn Error>>
Connect to a Chrome CDP page WebSocket using the default timeout.
Sourcepub async fn connect_with_timeout(
ws_url: &str,
timeout: Duration,
) -> Result<Self, Box<dyn Error>>
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.
Sourcepub fn subscribe_events(&self) -> Receiver<CdpEvent>
pub fn subscribe_events(&self) -> Receiver<CdpEvent>
Subscribe to method-only CDP events such as page lifecycle events.
Sourcepub fn subscribe_events_with_params(&self) -> Receiver<CdpEventWithParams>
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.
pub fn open_screencast_channel( &self, session_id: Option<String>, ) -> Result<Receiver<CdpScreencastFrame>, CdpError>
pub fn close_screencast_channel(&self) -> (u64, u64)
pub fn screencast_stats(&self) -> (u64, u64)
pub fn current_session_id(&self) -> Option<String>
pub async fn set_domain_enabled_for( &self, session_id: Option<String>, domain: &str, enabled: bool, ) -> Result<(), CdpError>
Sourcepub async fn send(
&self,
method: &str,
params: Option<Value>,
) -> Result<Value, CdpError>
pub async fn send( &self, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>
Send a CDP command and wait for the response.
Sourcepub async fn send_typed<R: DeserializeOwned>(
&self,
method: &str,
params: Option<Value>,
) -> Result<R, CdpError>
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.
Sourcepub async fn send_browser_typed<R: DeserializeOwned>(
&self,
method: &str,
params: Option<Value>,
) -> Result<R, CdpError>
pub async fn send_browser_typed<R: DeserializeOwned>( &self, method: &str, params: Option<Value>, ) -> Result<R, CdpError>
Typed variant of send_browser.
Sourcepub async fn send_to_session_typed<R: DeserializeOwned>(
&self,
session_id: &str,
method: &str,
params: Option<Value>,
) -> Result<R, CdpError>
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.
pub async fn send_browser( &self, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>
pub async fn send_to_session( &self, session_id: &str, method: &str, params: Option<Value>, ) -> Result<Value, CdpError>
Sourcepub async fn send_with_timeout(
&self,
method: &str,
params: Option<Value>,
timeout: Duration,
) -> Result<Value, CdpError>
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.
pub fn set_active_session(&self, session_id: Option<String>)
pub fn set_active_context(&self, context_id: Option<i64>)
pub fn set_active_frame_context( &self, frame_id: Option<String>, context_id: Option<i64>, )
pub fn set_active_route( &self, session_id: Option<String>, frame_id: Option<String>, context_id: Option<i64>, )
pub fn set_active_target_route( &self, target_id: Option<String>, session_id: Option<String>, frame_id: Option<String>, context_id: Option<i64>, )
pub fn operation_identity(&self) -> Option<(String, String)>
pub fn set_active_frame(&self, frame_id: Option<String>)
pub fn active_frame(&self) -> Option<String>
pub async fn with_current_route<F: Future>(&self, future: F) -> F::Output
pub async fn with_current_target_route<F: Future>(&self, future: F) -> F::Output
Sourcepub async fn frame_viewport_offset(
&self,
frame_id: &str,
) -> Result<(f64, f64), CdpError>
pub async fn frame_viewport_offset( &self, frame_id: &str, ) -> Result<(f64, f64), CdpError>
Return the selected child frame viewport origin in target coordinates.
Navigate to a URL.
Sourcepub async fn screenshot(&self, format: &str) -> Result<String, CdpError>
pub async fn screenshot(&self, format: &str) -> Result<String, CdpError>
Take a screenshot and return its base64-encoded image data.
pub async fn screenshot_with_params( &self, params: Value, ) -> Result<String, CdpError>
pub async fn get_layout_metrics(&self) -> Result<Value, CdpError>
Sourcepub async fn get_accessibility_tree(
&self,
) -> Result<AccessibilityTreeResponse, CdpError>
pub async fn get_accessibility_tree( &self, ) -> Result<AccessibilityTreeResponse, CdpError>
Get the accessibility tree.
Sourcepub async fn get_flattened_document(
&self,
depth: i64,
) -> Result<DomDocumentResponse, CdpError>
pub async fn get_flattened_document( &self, depth: i64, ) -> Result<DomDocumentResponse, CdpError>
Get a flattened document tree including shadow DOM content.
Uses pierce: true to include open shadow roots up to the given depth.
Sourcepub async fn get_deep_document(&self) -> Result<DomDocumentResponse, CdpError>
pub async fn get_deep_document(&self) -> Result<DomDocumentResponse, CdpError>
Get the full document tree for an explicit deep-DOM inspection.
Sourcepub async fn get_document_root(&self) -> Result<DomDocumentResponse, CdpError>
pub async fn get_document_root(&self) -> Result<DomDocumentResponse, CdpError>
Get only the document root for operations that do not need descendants.
Sourcepub async fn get_document(&self) -> Result<DomDocumentResponse, CdpError>
pub async fn get_document(&self) -> Result<DomDocumentResponse, CdpError>
Compatibility alias for the explicit deep-DOM request.
Sourcepub async fn query_selector(&self, selector: &str) -> Result<Value, CdpError>
pub async fn query_selector(&self, selector: &str) -> Result<Value, CdpError>
Query a CSS selector and return the matching node.
Sourcepub async fn resolve_node_object(
&self,
node_id: Option<i64>,
backend_node_id: Option<i64>,
) -> Result<String, CdpError>
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.
Sourcepub async fn backend_node_id_for_node(
&self,
node_id: i64,
) -> Result<i64, CdpError>
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.
Sourcepub async fn call_on_object(
&self,
object_id: &str,
function_declaration: &str,
) -> Result<RuntimeEvaluateResponse, CdpError>
pub async fn call_on_object( &self, object_id: &str, function_declaration: &str, ) -> Result<RuntimeEvaluateResponse, CdpError>
Invoke a function on a previously resolved remote object.
pub async fn release_object(&self, object_id: &str) -> Result<Value, CdpError>
pub async fn release_object_for_session( &self, session_id: &str, object_id: &str, ) -> Result<Value, CdpError>
Sourcepub async fn bounded_element_query(
&self,
expression: &str,
limit: usize,
) -> Result<(usize, Vec<i64>), CdpError>
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.
Sourcepub async fn get_box_model(&self, node_id: i64) -> Result<Value, CdpError>
pub async fn get_box_model(&self, node_id: i64) -> Result<Value, CdpError>
Get the bounding box of a DOM node.
Sourcepub async fn get_box_model_for_backend(
&self,
backend_node_id: i64,
) -> Result<Value, CdpError>
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.
Sourcepub async fn scroll_into_view_if_needed(
&self,
node_id: Option<i64>,
backend_node_id: Option<i64>,
) -> Result<Value, CdpError>
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.
Sourcepub async fn evaluate(
&self,
expression: &str,
) -> Result<RuntimeEvaluateResponse, CdpError>
pub async fn evaluate( &self, expression: &str, ) -> Result<RuntimeEvaluateResponse, CdpError>
Evaluate JavaScript in the page.
pub async fn evaluate_in_context( &self, expression: &str, context_id: Option<i64>, ) -> Result<RuntimeEvaluateResponse, CdpError>
Sourcepub async fn insert_text(&self, text: &str) -> Result<Value, CdpError>
pub async fn insert_text(&self, text: &str) -> Result<Value, CdpError>
Insert text into the currently focused element.
Sourcepub async fn dispatch_mouse_event(
&self,
event_type: &str,
x: f64,
y: f64,
button: Option<&str>,
click_count: Option<u32>,
) -> Result<Value, CdpError>
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.
Sourcepub 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>
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.
Sourcepub async fn dispatch_key_event(
&self,
event_type: &str,
key: &str,
code: &str,
) -> Result<Value, CdpError>
pub async fn dispatch_key_event( &self, event_type: &str, key: &str, code: &str, ) -> Result<Value, CdpError>
Dispatch a keyboard event via CDP Input.
pub async fn dispatch_key_event_with_modifiers( &self, event_type: &str, key: &str, code: &str, text: &str, modifiers: i64, ) -> Result<Value, CdpError>
Sourcepub async fn dispatch_select_all(&self) -> Result<Value, CdpError>
pub async fn dispatch_select_all(&self) -> Result<Value, CdpError>
Invoke Blink’s platform-independent editing command on the focused node.
pub async fn set_file_input_files( &self, node_id: Option<i64>, backend_node_id: Option<i64>, files: &[String], ) -> Result<Value, CdpError>
Sourcepub async fn scroll_by(&self, dx: f64, dy: f64) -> Result<Value, CdpError>
pub async fn scroll_by(&self, dx: f64, dy: f64) -> Result<Value, CdpError>
Scroll the current page by a delta in CSS pixels.
pub async fn enable_page(&self) -> Result<(), CdpError>
Sourcepub async fn enable_observation_events(&self) -> Result<(), CdpError>
pub async fn enable_observation_events(&self) -> Result<(), CdpError>
Enable the only event domains required to wait for navigation and invalidate compact observations.
pub async fn enable_observation_events_for( &self, session_id: &str, ) -> Result<(), CdpError>
pub async fn enable_runtime(&self) -> Result<(), CdpError>
pub async fn disable_runtime(&self) -> Result<(), CdpError>
pub async fn enable_log(&self) -> Result<(), CdpError>
pub async fn disable_log(&self) -> Result<(), CdpError>
pub async fn enable_network(&self) -> Result<(), CdpError>
pub async fn disable_network(&self) -> Result<(), CdpError>
pub async fn handle_javascript_dialog( &self, accept: bool, ) -> Result<Value, CdpError>
pub async fn set_download_behavior( &self, behavior: &str, download_path: Option<&Path>, events_enabled: bool, ) -> Result<Value, CdpError>
pub async fn enable_dom(&self) -> Result<(), CdpError>
pub async fn enable_accessibility(&self) -> Result<(), CdpError>
Sourcepub async fn close_browser(&self) -> Result<(), CdpError>
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.
Sourcepub async fn set_device_metrics_override(
&self,
width: i64,
height: i64,
device_scale_factor: f64,
mobile: bool,
) -> Result<Value, CdpError>
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.
Sourcepub async fn clear_device_metrics_override(&self) -> Result<Value, CdpError>
pub async fn clear_device_metrics_override(&self) -> Result<Value, CdpError>
Clear device metrics override.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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