feat: rename PageError to WebError (#26913)
This commit is contained in:
parent
9105a20ac4
commit
361038c950
|
|
@ -239,12 +239,12 @@ Use [`method: Page.waitForLoadState`] to wait until the page gets to a particula
|
||||||
cases).
|
cases).
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## event: BrowserContext.pageError
|
## event: BrowserContext.webError
|
||||||
* since: v1.38
|
* since: v1.38
|
||||||
- argument: <[PageError]>
|
- argument: <[WebError]>
|
||||||
|
|
||||||
Emitted when unhandled exceptions occur on any pages created through this
|
Emitted when exception is unhandled in any of the pages in this
|
||||||
context. To only listen for `pageError` events from a particular page, use [`event: Page.pageError`].
|
context. To listen for errors from a particular page, use [`event: Page.pageError`] instead.
|
||||||
|
|
||||||
## event: BrowserContext.request
|
## event: BrowserContext.request
|
||||||
* since: v1.12
|
* since: v1.12
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
# class: PageError
|
# class: WebError
|
||||||
* since: v1.38
|
* since: v1.38
|
||||||
|
|
||||||
[PageError] class represents objects created by context when there are unhandled
|
[WebError] class represents an unhandled exeception thrown in the page. It is dispatched via the [`event: BrowserContext.webError`] event.
|
||||||
execeptions thrown on the pages and dispatched via the [`event: BrowserContext.pageError`] event.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Log all uncaught errors to the terminal
|
// Log all uncaught errors to the terminal
|
||||||
context.on('pageerror', pageerror => {
|
context.on('weberror', webError => {
|
||||||
console.log(`Uncaught exception: "${pageerror.error()}"`);
|
console.log(`Uncaught exception: "${webError.error()}"`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Navigate to a page with an exception.
|
// Navigate to a page with an exception.
|
||||||
|
|
@ -16,8 +15,8 @@ await page.goto('data:text/html,<script>throw new Error("Test")</script>');
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Log all uncaught errors to the terminal
|
// Log all uncaught errors to the terminal
|
||||||
context.onPageError(pagerror -> {
|
context.onWebError(webError -> {
|
||||||
System.out.println("Uncaught exception: " + pagerror.error());
|
System.out.println("Uncaught exception: " + webError.error());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Navigate to a page with an exception.
|
// Navigate to a page with an exception.
|
||||||
|
|
@ -26,7 +25,7 @@ page.navigate("data:text/html,<script>throw new Error('Test')</script>");
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Log all uncaught errors to the terminal
|
# Log all uncaught errors to the terminal
|
||||||
context.on("pageerror", lambda pageerror: print(f"uncaught exception: {pageerror.error}"))
|
context.on("weberror", lambda web_error: print(f"uncaught exception: {web_error.error}"))
|
||||||
|
|
||||||
# Navigate to a page with an exception.
|
# Navigate to a page with an exception.
|
||||||
await page.goto("data:text/html,<script>throw new Error('test')</script>")
|
await page.goto("data:text/html,<script>throw new Error('test')</script>")
|
||||||
|
|
@ -34,7 +33,7 @@ await page.goto("data:text/html,<script>throw new Error('test')</script>")
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Log all uncaught errors to the terminal
|
# Log all uncaught errors to the terminal
|
||||||
context.on("pageerror", lambda pageerror: print(f"uncaught exception: {pageerror.error}"))
|
context.on("weberror", lambda web_error: print(f"uncaught exception: {web_error.error}"))
|
||||||
|
|
||||||
# Navigate to a page with an exception.
|
# Navigate to a page with an exception.
|
||||||
page.goto("data:text/html,<script>throw new Error('test')</script>")
|
page.goto("data:text/html,<script>throw new Error('test')</script>")
|
||||||
|
|
@ -42,25 +41,25 @@ page.goto("data:text/html,<script>throw new Error('test')</script>")
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Log all uncaught errors to the terminal
|
// Log all uncaught errors to the terminal
|
||||||
context.PageError += (_, pageerror) =>
|
context.WebError += (_, webError) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Uncaught exception: " + pageerror.Error);
|
Console.WriteLine("Uncaught exception: " + webError.Error);
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
## method: PageError.page
|
## method: WebError.page
|
||||||
* since: v1.38
|
* since: v1.38
|
||||||
- returns: <[null]|[Page]>
|
- returns: <[null]|[Page]>
|
||||||
|
|
||||||
The page that produced this unhandled exception, if any.
|
The page that produced this unhandled exception, if any.
|
||||||
|
|
||||||
## method: PageError.error
|
## method: WebError.error
|
||||||
* since: v1.38
|
* since: v1.38
|
||||||
- returns: <[Error]>
|
- returns: <[Error]>
|
||||||
|
|
||||||
Unhandled error that was thrown.
|
Unhandled error that was thrown.
|
||||||
|
|
||||||
## method: PageError.error
|
## method: WebError.error
|
||||||
* since: v1.38
|
* since: v1.38
|
||||||
* langs: java, csharp
|
* langs: java, csharp
|
||||||
- returns: <[string]>
|
- returns: <[string]>
|
||||||
|
|
@ -42,4 +42,4 @@ export { Video } from './video';
|
||||||
export { Worker } from './worker';
|
export { Worker } from './worker';
|
||||||
export { CDPSession } from './cdpSession';
|
export { CDPSession } from './cdpSession';
|
||||||
export { Playwright } from './playwright';
|
export { Playwright } from './playwright';
|
||||||
export { PageError } from './pageError';
|
export { WebError } from './webError';
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ import { rewriteErrorMessage } from '../utils/stackTrace';
|
||||||
import { HarRouter } from './harRouter';
|
import { HarRouter } from './harRouter';
|
||||||
import { ConsoleMessage } from './consoleMessage';
|
import { ConsoleMessage } from './consoleMessage';
|
||||||
import { Dialog } from './dialog';
|
import { Dialog } from './dialog';
|
||||||
import { PageError } from './pageError';
|
import { WebError } from './webError';
|
||||||
import { parseError } from '../protocol/serializers';
|
import { parseError } from '../protocol/serializers';
|
||||||
|
|
||||||
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel> implements api.BrowserContext {
|
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel> implements api.BrowserContext {
|
||||||
|
|
@ -105,7 +105,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
||||||
this._channel.on('pageError', ({ error, page }) => {
|
this._channel.on('pageError', ({ error, page }) => {
|
||||||
const pageObject = Page.from(page);
|
const pageObject = Page.from(page);
|
||||||
const parsedError = parseError(error);
|
const parsedError = parseError(error);
|
||||||
this.emit(Events.BrowserContext.PageError, new PageError(pageObject, parsedError));
|
this.emit(Events.BrowserContext.WebError, new WebError(pageObject, parsedError));
|
||||||
if (pageObject)
|
if (pageObject)
|
||||||
pageObject.emit(Events.Page.PageError, parsedError);
|
pageObject.emit(Events.Page.PageError, parsedError);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export const Events = {
|
||||||
Page: 'page',
|
Page: 'page',
|
||||||
// Can't use just 'error' due to node.js special treatment of error events.
|
// Can't use just 'error' due to node.js special treatment of error events.
|
||||||
// @see https://nodejs.org/api/events.html#events_error_events
|
// @see https://nodejs.org/api/events.html#events_error_events
|
||||||
PageError: 'pageerror',
|
WebError: 'weberror',
|
||||||
BackgroundPage: 'backgroundpage',
|
BackgroundPage: 'backgroundpage',
|
||||||
ServiceWorker: 'serviceworker',
|
ServiceWorker: 'serviceworker',
|
||||||
Request: 'request',
|
Request: 'request',
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
import type * as api from '../../types/types';
|
import type * as api from '../../types/types';
|
||||||
import type { Page } from './page';
|
import type { Page } from './page';
|
||||||
|
|
||||||
export class PageError implements api.PageError {
|
export class WebError implements api.WebError {
|
||||||
private _page: Page | null;
|
private _page: Page | null;
|
||||||
private _error: Error;
|
private _error: Error;
|
||||||
|
|
||||||
91
packages/playwright-core/types/types.d.ts
vendored
91
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -7625,11 +7625,10 @@ export interface BrowserContext {
|
||||||
on(event: 'page', listener: (page: Page) => void): this;
|
on(event: 'page', listener: (page: Page) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when unhandled exceptions occur on any pages created through this context. To only listen for `pageError`
|
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular
|
||||||
* events from a particular page, use
|
* page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead.
|
||||||
* [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error).
|
|
||||||
*/
|
*/
|
||||||
on(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
on(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
||||||
|
|
@ -7704,7 +7703,7 @@ export interface BrowserContext {
|
||||||
/**
|
/**
|
||||||
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
|
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
|
||||||
*/
|
*/
|
||||||
once(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
once(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
|
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
|
||||||
|
|
@ -7818,11 +7817,10 @@ export interface BrowserContext {
|
||||||
addListener(event: 'page', listener: (page: Page) => void): this;
|
addListener(event: 'page', listener: (page: Page) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when unhandled exceptions occur on any pages created through this context. To only listen for `pageError`
|
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular
|
||||||
* events from a particular page, use
|
* page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead.
|
||||||
* [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error).
|
|
||||||
*/
|
*/
|
||||||
addListener(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
addListener(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
||||||
|
|
@ -7897,7 +7895,7 @@ export interface BrowserContext {
|
||||||
/**
|
/**
|
||||||
* Removes an event listener added by `on` or `addListener`.
|
* Removes an event listener added by `on` or `addListener`.
|
||||||
*/
|
*/
|
||||||
removeListener(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
removeListener(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an event listener added by `on` or `addListener`.
|
* Removes an event listener added by `on` or `addListener`.
|
||||||
|
|
@ -7952,7 +7950,7 @@ export interface BrowserContext {
|
||||||
/**
|
/**
|
||||||
* Removes an event listener added by `on` or `addListener`.
|
* Removes an event listener added by `on` or `addListener`.
|
||||||
*/
|
*/
|
||||||
off(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
off(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an event listener added by `on` or `addListener`.
|
* Removes an event listener added by `on` or `addListener`.
|
||||||
|
|
@ -8066,11 +8064,10 @@ export interface BrowserContext {
|
||||||
prependListener(event: 'page', listener: (page: Page) => void): this;
|
prependListener(event: 'page', listener: (page: Page) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when unhandled exceptions occur on any pages created through this context. To only listen for `pageError`
|
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular
|
||||||
* events from a particular page, use
|
* page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead.
|
||||||
* [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error).
|
|
||||||
*/
|
*/
|
||||||
prependListener(event: 'pageerror', listener: (pageError: PageError) => void): this;
|
prependListener(event: 'weberror', listener: (webError: WebError) => void): this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
||||||
|
|
@ -8659,11 +8656,10 @@ export interface BrowserContext {
|
||||||
waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
|
waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when unhandled exceptions occur on any pages created through this context. To only listen for `pageError`
|
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular
|
||||||
* events from a particular page, use
|
* page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead.
|
||||||
* [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error).
|
|
||||||
*/
|
*/
|
||||||
waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (pageError: PageError) => boolean | Promise<boolean>, timeout?: number } | ((pageError: PageError) => boolean | Promise<boolean>)): Promise<PageError>;
|
waitForEvent(event: 'weberror', optionsOrPredicate?: { predicate?: (webError: WebError) => boolean | Promise<boolean>, timeout?: number } | ((webError: WebError) => boolean | Promise<boolean>)): Promise<WebError>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To
|
||||||
|
|
@ -17960,35 +17956,6 @@ export interface Mouse {
|
||||||
wheel(deltaX: number, deltaY: number): Promise<void>;
|
wheel(deltaX: number, deltaY: number): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link PageError} class represents objects created by context when there are unhandled execeptions thrown on the
|
|
||||||
* pages and dispatched via the
|
|
||||||
* [browserContext.on('pageerror')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-page-error)
|
|
||||||
* event.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* // 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>');
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export interface PageError {
|
|
||||||
/**
|
|
||||||
* Unhandled error that was thrown.
|
|
||||||
*/
|
|
||||||
error(): Error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The page that produced this unhandled exception, if any.
|
|
||||||
*/
|
|
||||||
page(): null|Page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object can be used to launch or connect to Chromium, returning instances of {@link Browser}.
|
* This object can be used to launch or connect to Chromium, returning instances of {@link Browser}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -19024,6 +18991,34 @@ export interface Video {
|
||||||
saveAs(path: string): Promise<void>;
|
saveAs(path: string): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link WebError} class represents an unhandled exeception thrown in the page. It is dispatched via the
|
||||||
|
* [browserContext.on('weberror')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-web-error)
|
||||||
|
* 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>');
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export interface WebError {
|
||||||
|
/**
|
||||||
|
* Unhandled error that was thrown.
|
||||||
|
*/
|
||||||
|
error(): Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page that produced this unhandled exception, if any.
|
||||||
|
*/
|
||||||
|
page(): null|Page;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link WebSocket} class represents websocket connections in the page.
|
* The {@link WebSocket} class represents websocket connections in the page.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -161,11 +161,11 @@ test('dialog event should work with inline script tag', async ({ page, server })
|
||||||
await expect.poll(() => popup.evaluate('window.result')).toBe('hello');
|
await expect.poll(() => popup.evaluate('window.result')).toBe('hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pageError event should work', async ({ page }) => {
|
test('weberror event should work', async ({ page }) => {
|
||||||
const [pageerror] = await Promise.all([
|
const [webError] = await Promise.all([
|
||||||
page.context().waitForEvent('pageerror'),
|
page.context().waitForEvent('weberror'),
|
||||||
page.setContent('<script>throw new Error("boom")</script>'),
|
page.setContent('<script>throw new Error("boom")</script>'),
|
||||||
]);
|
]);
|
||||||
expect(pageerror.page()).toBe(page);
|
expect(webError.page()).toBe(page);
|
||||||
expect(pageerror.error().stack).toContain('boom');
|
expect(webError.error().stack).toContain('boom');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue