+ fix #24466 + Adds support for exposing the `pageerror` events via `browserContext` API. + Helps with capturing the overall exceptions that are thrown outside of the the current page and also captures the exceptions happens on other windows/popups. + Keeps the API in sync with `context.on('request)', context.on('console'), etc..`
1.6 KiB
1.6 KiB
class: PageError
- since: v1.38
[PageError] class represents objects created by context when there are unhandled
execeptions thrown on the pages and dispatched via the [event: BrowserContext.pageError] event.
// Log all uncaught errors to the terminal
context.on('pageerror', pageerror => {
console.log(`Uncaught exception: "${pageerror.error()}"`);
});
// Navigate to a page with an exception.
await page.goto('data:text/html,<script>throw new Error("Test")</script>');
// Log all uncaught errors to the terminal
context.onPageError(pagerror -> {
System.out.println("Uncaught exception: " + pagerror.error());
});
// Navigate to a page with an exception.
page.navigate("data:text/html,<script>throw new Error('Test')</script>");
# Log all uncaught errors to the terminal
context.on("pageerror", lambda pageerror: print(f"uncaught exception: {pageerror.error}"))
# Navigate to a page with an exception.
await page.goto("data:text/html,<script>throw new Error('test')</script>")
# Log all uncaught errors to the terminal
context.on("pageerror", lambda pageerror: print(f"uncaught exception: {pageerror.error}"))
# Navigate to a page with an exception.
page.goto("data:text/html,<script>throw new Error('test')</script>")
// Log all uncaught errors to the terminal
context.PageError += (_, pageerror) =>
{
Console.WriteLine("Uncaught exception: " + pageerror.Error);
};
method: PageError.page
- since: v1.38
- returns: <[null]|[Page]>
The page that produced this unhandled exception, if any.
method: PageError.error
- since: v1.38
- returns: <[Error]>
Unhandled error that was thrown.