pub enum EventValue {
Show 14 variants
Page(Page),
Request(Request),
Response(ResponseObject),
Download(Download),
ConsoleMessage(ConsoleMessage),
FileChooser(FileChooser),
WebSocket(WebSocket),
Worker(Worker),
WebError(WebError),
Close,
Frame(Frame),
Load,
Crash,
PageError(String),
}Expand description
Typed value returned by the generic expect_event() method on Page and BrowserContext.
This enum covers the full set of events supported by expect_event().
Each variant wraps the event payload (or carries no data for unit events).
§Example
use playwright_rs::protocol::{EventValue, 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?;
let _ = page.goto("about:blank", None).await;
// Set up the waiter BEFORE the action that triggers the event
let waiter = page.expect_event("console", None).await?;
// Trigger the event
page.evaluate::<(), ()>("() => { console.log('hello'); }", None).await?;
// Resolve and match the result
match waiter.wait().await? {
EventValue::ConsoleMessage(msg) => println!("Got console: {}", msg.text()),
other => panic!("Unexpected: {:?}", other),
}
// Context-level: wait for a new page
let waiter = context.expect_event("page", None).await?;
let _p = context.new_page().await?;
match waiter.wait().await? {
EventValue::Page(p) => println!("New page: {}", p.url()),
other => panic!("Unexpected: {:?}", other),
}
browser.close().await?;
Ok(())
}See: https://playwright.dev/docs/api/class-page#page-wait-for-event
Variants§
Page(Page)
A new page was created (popup or context “page” event).
Request(Request)
A network request was issued.
Response(ResponseObject)
A network response was received.
Download(Download)
A file download started.
ConsoleMessage(ConsoleMessage)
A console message was produced.
FileChooser(FileChooser)
A file chooser dialog was opened.
WebSocket(WebSocket)
A web socket connection was opened.
Worker(Worker)
A web worker was created.
WebError(WebError)
A web error (uncaught exception) was reported — context level.
Close
The page or context was closed (no payload).
Frame(Frame)
A frame was attached, detached, or navigated.
Load
The page “load” event fired (no payload).
Crash
The page “crash” event fired (no payload).
PageError(String)
An uncaught JS exception was reported — carries the error message.
Trait Implementations§
Source§impl Clone for EventValue
impl Clone for EventValue
Source§fn clone(&self) -> EventValue
fn clone(&self) -> EventValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more