mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: use AbortSignal instead of AbortController (#10048)
This commit is contained in:
parent
5547e43829
commit
bbf2c0a8ec
@ -13,8 +13,8 @@ export interface WaitForSelectorOptions
|
|||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description | Default |
|
| Property | Modifiers | Type | Description | Default |
|
||||||
| --------------- | --------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
|
| -------- | --------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
|
||||||
| abortController | <code>optional</code> | AbortController | Provide an abort controller to cancel a waitForSelector call. | |
|
|
||||||
| hidden | <code>optional</code> | boolean | Wait for the selected element to not be found in the DOM or to be hidden, i.e. have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |
|
| hidden | <code>optional</code> | boolean | Wait for the selected element to not be found in the DOM or to be hidden, i.e. have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |
|
||||||
|
| signal | <code>optional</code> | AbortSignal | A signal object that allows you to cancel a waitForSelector call. | |
|
||||||
| timeout | <code>optional</code> | number | <p>Maximum time to wait in milliseconds. Pass <code>0</code> to disable timeout.</p><p>The default value can be changed by using [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md)</p> | <code>30_000</code> (30 seconds) |
|
| timeout | <code>optional</code> | number | <p>Maximum time to wait in milliseconds. Pass <code>0</code> to disable timeout.</p><p>The default value can be changed by using [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md)</p> | <code>30_000</code> (30 seconds) |
|
||||||
| visible | <code>optional</code> | boolean | Wait for the selected element to be present in DOM and to be visible, i.e. to not have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |
|
| visible | <code>optional</code> | boolean | Wait for the selected element to be present in DOM and to be visible, i.e. to not have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |
|
||||||
|
@ -73,9 +73,9 @@ export interface WaitForSelectorOptions {
|
|||||||
*/
|
*/
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
/**
|
/**
|
||||||
* Provide an abort controller to cancel a waitForSelector call.
|
* A signal object that allows you to cancel a waitForSelector call.
|
||||||
*/
|
*/
|
||||||
abortController?: AbortController;
|
signal?: AbortSignal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -435,7 +435,7 @@ export class IsolatedWorld {
|
|||||||
polling?: 'raf' | 'mutation' | number;
|
polling?: 'raf' | 'mutation' | number;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
root?: ElementHandle<Node>;
|
root?: ElementHandle<Node>;
|
||||||
abortController?: AbortController;
|
signal?: AbortSignal;
|
||||||
} = {},
|
} = {},
|
||||||
...args: Params
|
...args: Params
|
||||||
): Promise<HandleFor<Awaited<ReturnType<Func>>>> {
|
): Promise<HandleFor<Awaited<ReturnType<Func>>>> {
|
||||||
@ -443,7 +443,7 @@ export class IsolatedWorld {
|
|||||||
polling = 'raf',
|
polling = 'raf',
|
||||||
timeout = this.#timeoutSettings.timeout(),
|
timeout = this.#timeoutSettings.timeout(),
|
||||||
root,
|
root,
|
||||||
abortController,
|
signal,
|
||||||
} = options;
|
} = options;
|
||||||
if (typeof polling === 'number' && polling < 0) {
|
if (typeof polling === 'number' && polling < 0) {
|
||||||
throw new Error('Cannot poll with non-positive interval');
|
throw new Error('Cannot poll with non-positive interval');
|
||||||
@ -454,7 +454,7 @@ export class IsolatedWorld {
|
|||||||
polling,
|
polling,
|
||||||
root,
|
root,
|
||||||
timeout,
|
timeout,
|
||||||
abortController,
|
signal,
|
||||||
},
|
},
|
||||||
pageFunction as unknown as
|
pageFunction as unknown as
|
||||||
| ((...args: unknown[]) => Promise<Awaited<ReturnType<Func>>>)
|
| ((...args: unknown[]) => Promise<Awaited<ReturnType<Func>>>)
|
||||||
|
@ -167,10 +167,10 @@ export class QueryHandler {
|
|||||||
element = await frame.worlds[PUPPETEER_WORLD].adoptHandle(elementOrFrame);
|
element = await frame.worlds[PUPPETEER_WORLD].adoptHandle(elementOrFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {visible = false, hidden = false, timeout, abortController} = options;
|
const {visible = false, hidden = false, timeout, signal} = options;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (options.abortController?.signal.aborted) {
|
if (signal?.aborted) {
|
||||||
throw new AbortError('QueryHander.waitFor has been aborted.');
|
throw new AbortError('QueryHander.waitFor has been aborted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ export class QueryHandler {
|
|||||||
polling: visible || hidden ? 'raf' : 'mutation',
|
polling: visible || hidden ? 'raf' : 'mutation',
|
||||||
root: element,
|
root: element,
|
||||||
timeout,
|
timeout,
|
||||||
abortController,
|
signal,
|
||||||
},
|
},
|
||||||
LazyArg.create(context => {
|
LazyArg.create(context => {
|
||||||
return context.puppeteerUtil;
|
return context.puppeteerUtil;
|
||||||
@ -201,7 +201,7 @@ export class QueryHandler {
|
|||||||
visible ? true : hidden ? false : undefined
|
visible ? true : hidden ? false : undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
if (options.abortController?.signal.aborted) {
|
if (signal?.aborted) {
|
||||||
await handle.dispose();
|
await handle.dispose();
|
||||||
throw new AbortError('QueryHander.waitFor has been aborted.');
|
throw new AbortError('QueryHander.waitFor has been aborted.');
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ export interface WaitTaskOptions {
|
|||||||
polling: 'raf' | 'mutation' | number;
|
polling: 'raf' | 'mutation' | number;
|
||||||
root?: ElementHandle<Node>;
|
root?: ElementHandle<Node>;
|
||||||
timeout: number;
|
timeout: number;
|
||||||
abortController?: AbortController;
|
signal?: AbortSignal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ export class WaitTask<T = unknown> {
|
|||||||
#result = createDeferredPromise<HandleFor<T>>();
|
#result = createDeferredPromise<HandleFor<T>>();
|
||||||
|
|
||||||
#poller?: JSHandle<Poller<T>>;
|
#poller?: JSHandle<Poller<T>>;
|
||||||
#abortController?: AbortController;
|
#signal?: AbortSignal;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
world: IsolatedWorld,
|
world: IsolatedWorld,
|
||||||
@ -62,8 +62,8 @@ export class WaitTask<T = unknown> {
|
|||||||
this.#world = world;
|
this.#world = world;
|
||||||
this.#polling = options.polling;
|
this.#polling = options.polling;
|
||||||
this.#root = options.root;
|
this.#root = options.root;
|
||||||
this.#abortController = options.abortController;
|
this.#signal = options.signal;
|
||||||
this.#abortController?.signal?.addEventListener(
|
this.#signal?.addEventListener(
|
||||||
'abort',
|
'abort',
|
||||||
() => {
|
() => {
|
||||||
this.terminate(new AbortError('WaitTask has been aborted.'));
|
this.terminate(new AbortError('WaitTask has been aborted.'));
|
||||||
|
@ -386,7 +386,7 @@ describe('waittask specs', function () {
|
|||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
const task = page.waitForSelector('wrong', {
|
const task = page.waitForSelector('wrong', {
|
||||||
abortController,
|
signal: abortController.signal,
|
||||||
});
|
});
|
||||||
abortController.abort();
|
abortController.abort();
|
||||||
expect(task).rejects.toThrow(/aborted/);
|
expect(task).rejects.toThrow(/aborted/);
|
||||||
|
Loading…
Reference in New Issue
Block a user