Expand description
CDPSession — Chrome DevTools Protocol session
Provides access to the Chrome DevTools Protocol for Chromium-based browsers.
CDPSession is created via BrowserContext::new_cdp_session.
§Example
ⓘ
use playwright_rs::protocol::Playwright;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let playwright = Playwright::launch().await?;
let browser = playwright.chromium().launch().await?;
let context = browser.new_context().await?;
let page = context.new_page().await?;
// Create a CDP session for the page
let session = context.new_cdp_session(&page).await?;
// Send a CDP command
let result = session
.send("Runtime.evaluate", Some(serde_json::json!({ "expression": "1+1" })))
.await?;
println!("Result: {:?}", result);
session.detach().await?;
context.close().await?;
browser.close().await?;
Ok(())
}Structs§
- CDPSession
- A Chrome DevTools Protocol session for a page or browser context.