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 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
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WebError
impl !RefUnwindSafe for WebError
impl Send for WebError
impl Sync for WebError
impl Unpin for WebError
impl UnsafeUnpin for WebError
impl !UnwindSafe for WebError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more