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
impl ManagedSession
Sourcepub fn new(session: CdpSession) -> Self
pub fn new(session: CdpSession) -> Self
Wrap a CdpSession with domain tracking.
Sourcepub async fn ensure_domain(&mut self, domain: &str) -> Result<(), CdpError>
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.
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>
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Get the underlying session ID.
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 within this session.
§Errors
Returns CdpError if the transport task has exited.
Sourcepub fn enabled_domains(&self) -> &HashSet<String>
pub fn enabled_domains(&self) -> &HashSet<String>
Returns the set of currently enabled domains.
Sourcepub async fn spawn_auto_dismiss(&mut self) -> Result<JoinHandle<()>, CdpError>
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.