pub struct CDPSession { /* private fields */ }Expand description
A Chrome DevTools Protocol session for a page or browser context.
CDPSession is only available in Chromium-based browsers.
Implementations§
Source§impl CDPSession
impl CDPSession
Sourcepub fn new(
parent: ParentOrConnection,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: ParentOrConnection, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new CDPSession from protocol initialization.
Called by the object factory when the server sends a __create__ message.
Sourcepub async fn send(&self, method: &str, params: Option<Value>) -> Result<Value>
pub async fn send(&self, method: &str, params: Option<Value>) -> Result<Value>
Send a CDP command and return the result.
§Arguments
method- The CDP method name (e.g.,"Runtime.evaluate")params- Optional JSON parameters for the method
§Errors
Returns error if:
- The session has been detached
- The CDP method fails
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-cdpsession#cdp-session-send
Sourcepub fn on<F, Fut>(&self, method: impl Into<String>, handler: F)
pub fn on<F, Fut>(&self, method: impl Into<String>, handler: F)
Register a handler for a CDP event by method name. Multiple handlers
may be registered for the same method; they fire in registration
order. The Playwright server forwards every CDP event the
underlying session emits — no Playwright-side subscription is
needed, but you typically must enable the CDP domain itself first
(e.g. session.send("Network.enable", None).await? before
expecting Network.requestWillBeSent).
See: https://playwright.dev/docs/api/class-cdpsession#cdp-session-on
Sourcepub fn on_close<F, Fut>(&self, handler: F)
pub fn on_close<F, Fut>(&self, handler: F)
Register a handler for the close event, fired when the session
is detached (parent target closes, browser closes, or
detach is called).
See: https://playwright.dev/docs/api/class-cdpsession#cdp-session-event-close
Sourcepub async fn detach(&self) -> Result<()>
pub async fn detach(&self) -> Result<()>
Detach the CDP session from the target.
After detaching, the session can no longer be used to send commands.
§Errors
Returns error if:
- The session has already been detached
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-cdpsession#cdp-session-detach
Trait Implementations§
Source§impl Clone for CDPSession
impl Clone for CDPSession
Source§fn clone(&self) -> CDPSession
fn clone(&self) -> CDPSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more