1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2026 Paul Adamson
// Licensed under the Apache License, Version 2.0
//
// WebError - plain data struct constructed from the pageError event params.
//
// WebError is NOT a ChannelOwner. It is constructed inline in
// BrowserContext::on_event("pageError") when the context-level weberror event
// is dispatched.
//
// See: <https://playwright.dev/docs/api/class-weberror>
/// 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`](crate::protocol::Page)
/// that threw the error.
///
/// # Example
///
/// ```ignore
/// 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(())
/// }
/// ```
///
/// See: <https://playwright.dev/docs/api/class-weberror>