mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: use AbortSignal.throwIfAborted (#10105)
This commit is contained in:
parent
a856f8ff76
commit
575f00a31d
@ -8,7 +8,6 @@ sidebar_label: API
|
|||||||
|
|
||||||
| Class | Description |
|
| Class | Description |
|
||||||
| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [AbortError](./puppeteer.aborterror.md) | AbortError is emitted whenever certain operations are terminated due to an abort request. |
|
|
||||||
| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). |
|
| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). |
|
||||||
| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a browser instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). |
|
| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a browser instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). |
|
||||||
| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
|
| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: AbortError
|
|
||||||
---
|
|
||||||
|
|
||||||
# AbortError class
|
|
||||||
|
|
||||||
AbortError is emitted whenever certain operations are terminated due to an abort request.
|
|
||||||
|
|
||||||
#### Signature:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare class AbortError extends CustomError
|
|
||||||
```
|
|
||||||
|
|
||||||
**Extends:** [CustomError](./puppeteer.customerror.md)
|
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
Example operations are [page.waitForSelector](./puppeteer.page.waitforselector.md).
|
|
@ -42,17 +42,6 @@ export class CustomError extends Error {
|
|||||||
*/
|
*/
|
||||||
export class TimeoutError extends CustomError {}
|
export class TimeoutError extends CustomError {}
|
||||||
|
|
||||||
/**
|
|
||||||
* AbortError is emitted whenever certain operations are terminated due to
|
|
||||||
* an abort request.
|
|
||||||
*
|
|
||||||
* @remarks
|
|
||||||
* Example operations are {@link Page.waitForSelector | page.waitForSelector}.
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export class AbortError extends CustomError {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProtocolError is emitted whenever there is an error from the protocol.
|
* ProtocolError is emitted whenever there is an error from the protocol.
|
||||||
*
|
*
|
||||||
|
@ -20,7 +20,6 @@ import {assert} from '../util/assert.js';
|
|||||||
import {isErrorLike} from '../util/ErrorLike.js';
|
import {isErrorLike} from '../util/ErrorLike.js';
|
||||||
import {interpolateFunction, stringifyFunction} from '../util/Function.js';
|
import {interpolateFunction, stringifyFunction} from '../util/Function.js';
|
||||||
|
|
||||||
import {AbortError} from './Errors.js';
|
|
||||||
import type {Frame} from './Frame.js';
|
import type {Frame} from './Frame.js';
|
||||||
import {transposeIterableHandle} from './HandleIterator.js';
|
import {transposeIterableHandle} from './HandleIterator.js';
|
||||||
import type {WaitForSelectorOptions} from './IsolatedWorld.js';
|
import type {WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||||
@ -170,9 +169,7 @@ export class QueryHandler {
|
|||||||
const {visible = false, hidden = false, timeout, signal} = options;
|
const {visible = false, hidden = false, timeout, signal} = options;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (signal?.aborted) {
|
signal?.throwIfAborted();
|
||||||
throw new AbortError('QueryHander.waitFor has been aborted.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const handle = await frame.worlds[PUPPETEER_WORLD].waitForFunction(
|
const handle = await frame.worlds[PUPPETEER_WORLD].waitForFunction(
|
||||||
async (PuppeteerUtil, query, selector, root, visible) => {
|
async (PuppeteerUtil, query, selector, root, visible) => {
|
||||||
@ -203,7 +200,7 @@ export class QueryHandler {
|
|||||||
|
|
||||||
if (signal?.aborted) {
|
if (signal?.aborted) {
|
||||||
await handle.dispose();
|
await handle.dispose();
|
||||||
throw new AbortError('QueryHander.waitFor has been aborted.');
|
throw signal.reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(handle instanceof ElementHandle)) {
|
if (!(handle instanceof ElementHandle)) {
|
||||||
@ -215,6 +212,9 @@ export class QueryHandler {
|
|||||||
if (!isErrorLike(error)) {
|
if (!isErrorLike(error)) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
if (error.name === 'AbortError') {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
error.message = `Waiting for selector \`${selector}\` failed: ${error.message}`;
|
error.message = `Waiting for selector \`${selector}\` failed: ${error.message}`;
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -20,7 +20,7 @@ import type {Poller} from '../injected/Poller.js';
|
|||||||
import {createDeferredPromise} from '../util/DeferredPromise.js';
|
import {createDeferredPromise} from '../util/DeferredPromise.js';
|
||||||
import {stringifyFunction} from '../util/Function.js';
|
import {stringifyFunction} from '../util/Function.js';
|
||||||
|
|
||||||
import {TimeoutError, AbortError} from './Errors.js';
|
import {TimeoutError} from './Errors.js';
|
||||||
import {IsolatedWorld} from './IsolatedWorld.js';
|
import {IsolatedWorld} from './IsolatedWorld.js';
|
||||||
import {LazyArg} from './LazyArg.js';
|
import {LazyArg} from './LazyArg.js';
|
||||||
import {HandleFor} from './types.js';
|
import {HandleFor} from './types.js';
|
||||||
@ -66,7 +66,7 @@ export class WaitTask<T = unknown> {
|
|||||||
this.#signal?.addEventListener(
|
this.#signal?.addEventListener(
|
||||||
'abort',
|
'abort',
|
||||||
() => {
|
() => {
|
||||||
void this.terminate(new AbortError('WaitTask has been aborted.'));
|
void this.terminate(this.#signal?.reason);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
once: true,
|
once: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user