Skip to main content

Crate playwright_cdp

Crate playwright_cdp 

Source
Expand description

§playwright-cdp

Drive Chromium-based browsers directly via the Chrome DevTools Protocol (CDP) over a single WebSocket — no Playwright Node.js driver required.

The public API mirrors Playwright’s shape (Playwright, BrowserType, Browser, BrowserContext, Page, Locator, builder option structs, async + Result<T>), but it speaks CDP natively instead of proxying through Playwright’s driver.

// Three-layer entry, mirroring playwright-rust (no driver spawned here).
let browser = Playwright::launch().await?
    .chromium()
    .launch_with_options(LaunchOptions::default()).await?;
let page = browser.new_page().await?;
page.goto("https://example.com", None).await?;
let title: String = page.evaluate("document.title").await?;
println!("{title}");
browser.close().await?;

Browser::launch also works directly for callers who don’t need the Playwright/BrowserType layer.

Re-exports§

pub use api_request::APIRequestContext;
pub use api_request::APIResponse;
pub use api_request::ApiRequestContextOptions;
pub use assertions::expect;
pub use assertions::expect_page;
pub use assertions::LocatorAssertions;
pub use assertions::PageAssertions;
pub use browser::Browser;
pub use browser_context::BrowserContext;
pub use browser_type::BrowserType;
pub use browser_type::Engine;
pub use cdp::session::CdpSession;
pub use download::Download;
pub use element_handle::ElementHandle;
pub use error::Error;
pub use error::Result;
pub use file_chooser::FileChooser;
pub use frame::Frame;
pub use frame_locator::FrameLocator;
pub use keyboard::Keyboard;
pub use locator::Locator;
pub use mouse::Mouse;
pub use page::Dialog;
pub use page::Page;
pub use playwright::Playwright;
pub use request::Request;
pub use response::Response;
pub use options::APIRequestOptions;
pub use route::Route;
pub use route::RouteContinueOptions;
pub use route::RouteFetchOptions;
pub use route::RouteFetchResponse;
pub use route::RouteFulfillOptions;
pub use types::AriaRole;
pub use types::ConsoleMessage;
pub use types::MouseButton;
pub use types::NameValue;
pub use types::OriginStorage;
pub use types::Position;
pub use types::StorageState;
pub use types::Viewport;
pub use tracing::Tracing;
pub use touchscreen::Touchscreen;
pub use worker::Worker;
pub use accessibility::Accessibility;
pub use accessibility::AccessibilityNode;
pub use accessibility::AccessibilitySnapshotOptions;
pub use clock::Clock;
pub use clock::ClockInstallOptions;
pub use coverage::Coverage;
pub use coverage::CSSCoverageEntry;
pub use coverage::CSSCoverageResult;
pub use coverage::JSCoverageEntry;
pub use coverage::JSCoverageResult;
pub use element_handle::ElementState;
pub use har::Har;
pub use har::HarEntry;
pub use har::HarRecorder;
pub use har::HarRequest;
pub use har::HarResponse;
pub use har::RouteFromHarOptions;
pub use js_handle::JSHandle;
pub use video::Video;
pub use video::VideoStartOptions;
pub use web_socket::FrameData;
pub use web_socket::FrameDirection;
pub use web_socket::WebSocket;
pub use web_socket::WebSocketFrame;
pub use web_socket::WebSocketHandshake;
pub use web_socket::WebSocketLiveEvent;
pub use web_storage::WebStorage;

Modules§

accessibility
Accessibility — accessibility-tree snapshot via the CDP Accessibility domain.
api_request
Standalone HTTP client mirroring Playwright’s APIRequestContext / APIResponse.
assertions
Playwright-style expect(locator) / expect(page) assertions.
browser
Browser — top-level entry point. Launches/connects to Chromium over CDP.
browser_context
BrowserContext — an isolated context (incognito-style), owning pages, init scripts, cookies, and defaults.
browser_process
Chrome/Chromium process management: executable discovery, spawning with --remote-debugging-port, DevToolsActivePort discovery, and /json/version resolution to the browser WebSocket endpoint.
browser_type
BrowserType — a browser engine entry point (Playwright-shaped).
cdp
Low-level CDP plumbing: WebSocket transport, wire-format messages, the multiplexing connection, and the per-target session.
clock
Clock — Playwright-style fake timers for a page.
coverage
Coverage — JS and CSS code-coverage collection for a page.
download
Download — file-download capture via the CDP Page download events.
element_handle
ElementHandle — a persistent handle to a resolved DOM element (a CDP RemoteObjectId).
error
Error types for the crate.
file_chooser
FileChooser — file-chooser interception via the CDP Page domain.
frame
Frame — a frame within a page (the main document, or an <iframe>).
frame_locator
FrameLocator — a Playwright-style locator scoped to a same-origin <iframe>’s contentDocument.
har
HAR recording/replay (route_from_har).
js_handle
JSHandle — a reference to a remote JavaScript object (a CDP RemoteObjectId) on a session.
keyboard
Keyboard — input via the CDP Input domain.
locator
Locator — a Playwright-style element reference resolved lazily against the page’s selector engine.
mouse
Mouse — pointer input via the CDP Input domain.
options
Builder option structs mirroring Playwright’s option objects.
page
Page — a browser tab. Tracks its main execution context, drives navigation, evaluation, screenshots, and produces locators.
playwright
Playwright — the top-level entry point (Playwright-shaped).
request
Request — an HTTP request observed via the CDP Network domain.
response
Response — an HTTP response observed via the CDP Network domain.
route
Route — network interception via the CDP Fetch domain.
selectors
Selector-engine injection and element resolution.
touchscreen
Touchscreen — touch input via the CDP Input.dispatchTouchEvent.
tracing
Tracing — performance tracing via the browser-level CDP Tracing domain.
types
Shared value types used across the public API.
video
Video — page video capture via CDP Page.startScreencast.
web_socket
WebSocket — a captured WebSocket connection, reconstructed from CDP Network.webSocket* events.
web_storage
WebStoragelocalStorage / sessionStorage access via the CDP DOMStorage domain.
worker
Worker — web/service/shared-worker capture via the CDP Target domain.

Structs§

SecurityDetails
TLS/SSL certificate details, derived from the CDP Network.Response.securityDetails object.
ServerAddr
The remote server address a response came from.
Sizes
Size breakdown for a transferred resource, derived from CDP Network.loadingFinished (encodedDataLength) and the response headers.
Timing
Timing information for a request/response, derived from the CDP Network.Response.timing object. All times are Unix epoch milliseconds where applicable; durations are milliseconds.