Skip to main content

ManagedSession

Struct ManagedSession 

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

A CDP session wrapper that tracks which domains have been enabled, ensuring each domain is only enabled once (lazy domain enabling).

This fulfills AC13: “only the required domains are enabled” per command.

Implementations§

Source§

impl ManagedSession

Source

pub fn new(session: CdpSession) -> Self

Wrap a CdpSession with domain tracking.

Source

pub async fn ensure_domain(&mut self, domain: &str) -> Result<(), CdpError>

Ensure a CDP domain is enabled. Sends {domain}.enable only if the domain has not already been enabled in this session.

§Errors

Returns CdpError if the enable command fails.

Source

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

Send a command within this session.

§Errors

Returns CdpError if the command fails.

Source

pub fn session_id(&self) -> &str

Get the underlying session ID.

Source

pub async fn subscribe( &self, method: &str, ) -> Result<Receiver<CdpEvent>, CdpError>

Subscribe to CDP events matching a method name within this session.

§Errors

Returns CdpError if the transport task has exited.

Source

pub fn enabled_domains(&self) -> &HashSet<String>

Returns the set of currently enabled domains.

Source

pub async fn install_dialog_interceptors(&self)

Install dialog interceptor scripts that override window.alert, window.confirm, and window.prompt to store dialog metadata in a cookie named __chrome_cli_dialog before calling the original function.

This enables dialog info and dialog handle to retrieve dialog type, message, and default value via Network.getCookies even when the dialog was opened before the current CDP session was created.

This method is best-effort: errors are silently ignored so that failure to install interceptors never breaks the calling command.

Source

pub async fn spawn_auto_dismiss(&mut self) -> Result<JoinHandle<()>, CdpError>

Spawn a background task that automatically dismisses JavaScript dialogs.

Subscribes to dialog events and sends Page.enable with a short timeout. If a dialog is already open, Page.enable will block, but Chrome re-emits the Page.javascriptDialogOpening event before blocking, so the pre-existing dialog is captured and dismissed. Returns a JoinHandle whose abort() method can be called to stop the task (or it stops naturally when the session is dropped).

§Errors

Returns CdpError if the event subscription fails.

Trait Implementations§

Source§

impl Debug for ManagedSession

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