playwright/docs/src/api/class-pageerror.md

1.8 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.

method: PageError.error

  • since: v1.38
  • langs: java, csharp
  • returns: <[string]>

Unhandled error that was thrown.