跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

WebError ​

Added in: v1.38

WebError class represents an unhandled exception thrown in the page. It is dispatched via the browserContext.on('webError') event.

js
// Log all uncaught errors to the terminal
context.on('weberror', webError => {
  console.log(`Uncaught exception: "${webError.error()}"`);
});

// Navigate to a page with an exception.
await page.goto('data:text/html,<script>throw new Error("Test")</script>');

Methods ​

webError.error() ​

Added in: v1.38

Unhandled error that was thrown.

Returns

  • Error

webError.location() ​

Added in: v1.60

Returns

  • Object

webError.page() ​

Added in: v1.38

The page that produced this unhandled exception, if any.

Returns

  • null | Page

基于 Apache 2.0 许可证发布。