2023-09-06 12:40:53 -07:00
|
|
|
# class: WebError
|
2023-08-17 09:10:03 -07:00
|
|
|
* since: v1.38
|
|
|
|
|
2023-10-04 22:56:42 -04:00
|
|
|
[WebError] class represents an unhandled exception thrown in the page. It is dispatched via the [`event: BrowserContext.webError`] event.
|
2023-08-17 09:10:03 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
// Log all uncaught errors to the terminal
|
2023-09-06 12:40:53 -07:00
|
|
|
context.on('weberror', webError => {
|
|
|
|
console.log(`Uncaught exception: "${webError.error()}"`);
|
2023-08-17 09:10:03 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Navigate to a page with an exception.
|
|
|
|
await page.goto('data:text/html,<script>throw new Error("Test")</script>');
|
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
|
|
|
// Log all uncaught errors to the terminal
|
2023-09-06 12:40:53 -07:00
|
|
|
context.onWebError(webError -> {
|
|
|
|
System.out.println("Uncaught exception: " + webError.error());
|
2023-08-17 09:10:03 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Navigate to a page with an exception.
|
|
|
|
page.navigate("data:text/html,<script>throw new Error('Test')</script>");
|
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
|
|
|
# Log all uncaught errors to the terminal
|
2023-09-06 12:40:53 -07:00
|
|
|
context.on("weberror", lambda web_error: print(f"uncaught exception: {web_error.error}"))
|
2023-08-17 09:10:03 -07:00
|
|
|
|
|
|
|
# Navigate to a page with an exception.
|
|
|
|
await page.goto("data:text/html,<script>throw new Error('test')</script>")
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
# Log all uncaught errors to the terminal
|
2023-09-06 12:40:53 -07:00
|
|
|
context.on("weberror", lambda web_error: print(f"uncaught exception: {web_error.error}"))
|
2023-08-17 09:10:03 -07:00
|
|
|
|
|
|
|
# Navigate to a page with an exception.
|
|
|
|
page.goto("data:text/html,<script>throw new Error('test')</script>")
|
|
|
|
```
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
// Log all uncaught errors to the terminal
|
2023-09-06 12:40:53 -07:00
|
|
|
context.WebError += (_, webError) =>
|
2023-08-17 09:10:03 -07:00
|
|
|
{
|
2023-09-06 12:40:53 -07:00
|
|
|
Console.WriteLine("Uncaught exception: " + webError.Error);
|
2023-08-17 09:10:03 -07:00
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2023-09-06 12:40:53 -07:00
|
|
|
## method: WebError.page
|
2023-08-17 09:10:03 -07:00
|
|
|
* since: v1.38
|
|
|
|
- returns: <[null]|[Page]>
|
|
|
|
|
|
|
|
The page that produced this unhandled exception, if any.
|
|
|
|
|
2023-09-06 12:40:53 -07:00
|
|
|
## method: WebError.error
|
2023-08-17 09:10:03 -07:00
|
|
|
* since: v1.38
|
|
|
|
- returns: <[Error]>
|
|
|
|
|
|
|
|
Unhandled error that was thrown.
|
|
|
|
|
2023-09-06 12:40:53 -07:00
|
|
|
## method: WebError.error
|
2023-08-23 14:31:18 -07:00
|
|
|
* since: v1.38
|
|
|
|
* langs: java, csharp
|
|
|
|
- returns: <[string]>
|
|
|
|
|
|
|
|
Unhandled error that was thrown.
|