pub struct WebError { /* private fields */ }Expand description
Represents an uncaught JavaScript exception thrown on any page in a browser context.
WebError is the context-level companion to the page-level on_pageerror event.
It wraps the error message alongside an optional back-reference to the Page
that threw the error.
§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?;
context
.on_weberror(|web_error| async move {
println!(
"Uncaught error on page {:?}: {}",
web_error.page().map(|p| p.url()),
web_error.error()
);
Ok(())
})
.await?;
let page = context.new_page().await?;
page.goto("about:blank", None).await?;
// Trigger an uncaught error asynchronously
let _ = page
.evaluate_expression("setTimeout(() => { throw new Error('boom') }, 0)")
.await;
browser.close().await?;
Ok(())
}Implementations§
Source§impl WebError
impl WebError
Sourcepub fn location(&self) -> Option<&WebErrorLocation>
pub fn location(&self) -> Option<&WebErrorLocation>
Returns the source location of the uncaught exception, if reported (script URL, line, column).
See: https://playwright.dev/docs/api/class-weberror#web-error-location
Sourcepub fn page(&self) -> Option<&Page>
pub fn page(&self) -> Option<&Page>
Returns the page that produced this error, if available.
May be None if the page has already been closed or the page reference
could not be resolved from the connection registry.
See: https://playwright.dev/docs/api/class-weberror#web-error-page
Sourcepub fn error(&self) -> &str
pub fn error(&self) -> &str
Returns the error message of the uncaught JavaScript exception.
See: https://playwright.dev/docs/api/class-weberror#web-error-error