Skip to content

Commit 953dd36

Browse files
authored
feat(api): remove 'mutation' polling option (#2048)
It is not compatible with shadow dom.
1 parent 4afd391 commit 953dd36

File tree

5 files changed

+8
-50
lines changed

5 files changed

+8
-50
lines changed

docs/api.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,9 +1702,7 @@ is fired.
17021702
- `pageFunction` <[function]|[string]> Function to be evaluated in browser context
17031703
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
17041704
- `options` <[Object]> Optional waiting parameters
1705-
- `polling` <[number]|"raf"|"mutation"> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values:
1706-
- `'raf'` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes.
1707-
- `'mutation'` - to execute `pageFunction` on every DOM mutation.
1705+
- `polling` <[number]|"raf"> If `polling` is `'raf'`, then `pageFunction` is constantly executed in `requestAnimationFrame` callback. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`.
17081706
- `timeout` <[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method.
17091707
- returns: <[Promise]<[JSHandle]>> Promise which resolves when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.
17101708

@@ -2371,9 +2369,7 @@ Returns frame's url.
23712369
- `pageFunction` <[function]|[string]> Function to be evaluated in browser context
23722370
- `arg` <[Serializable]|[JSHandle]> Optional argument to pass to `pageFunction`
23732371
- `options` <[Object]> Optional waiting parameters
2374-
- `polling` <[number]|"raf"|"mutation"> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values:
2375-
- `'raf'` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes.
2376-
- `'mutation'` - to execute `pageFunction` on every DOM mutation.
2372+
- `polling` <[number]|"raf"> If `polling` is `'raf'`, then `pageFunction` is constantly executed in `requestAnimationFrame` callback. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`.
23772373
- `timeout` <[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
23782374
- returns: <[Promise]<[JSHandle]>> Promise which resolves when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.
23792375

src/frames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ export class Frame {
770770
const { polling = 'raf' } = options;
771771
const deadline = this._page._timeoutSettings.computeDeadline(options);
772772
if (helper.isString(polling))
773-
assert(polling === 'raf' || polling === 'mutation', 'Unknown polling option: ' + polling);
773+
assert(polling === 'raf', 'Unknown polling option: ' + polling);
774774
else if (helper.isNumber(polling))
775775
assert(polling > 0, 'Cannot poll with non-positive interval: ' + polling);
776776
else

src/injected/injected.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,6 @@ export class Injected {
3535
return rect.width > 0 && rect.height > 0;
3636
}
3737

38-
private _pollMutation<T>(predicate: Predicate<T>, timeout: number): Promise<T | undefined> {
39-
let timedOut = false;
40-
if (timeout)
41-
setTimeout(() => timedOut = true, timeout);
42-
43-
const success = predicate();
44-
if (success)
45-
return Promise.resolve(success);
46-
47-
let fulfill: (result?: any) => void;
48-
const result = new Promise<T | undefined>(x => fulfill = x);
49-
const observer = new MutationObserver(() => {
50-
if (timedOut) {
51-
observer.disconnect();
52-
fulfill();
53-
return;
54-
}
55-
const success = predicate();
56-
if (success) {
57-
observer.disconnect();
58-
fulfill(success);
59-
}
60-
});
61-
observer.observe(document, {
62-
childList: true,
63-
subtree: true,
64-
attributes: true
65-
});
66-
return result;
67-
}
68-
6938
private _pollRaf<T>(predicate: Predicate<T>, timeout: number): Promise<T | undefined> {
7039
let timedOut = false;
7140
if (timeout)
@@ -113,11 +82,9 @@ export class Injected {
11382
return result;
11483
}
11584

116-
poll<T>(polling: 'raf' | 'mutation' | number, timeout: number, predicate: Predicate<T>): Promise<T | undefined> {
85+
poll<T>(polling: 'raf' | number, timeout: number, predicate: Predicate<T>): Promise<T | undefined> {
11786
if (polling === 'raf')
11887
return this._pollRaf(predicate, timeout);
119-
if (polling === 'mutation')
120-
return this._pollMutation(predicate, timeout);
12188
return this._pollInterval(polling, predicate, timeout);
12289
}
12390

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type TimeoutOptions = { timeout?: number };
3939

4040
export type WaitForElementOptions = TimeoutOptions & { waitFor?: 'attached' | 'detached' | 'visible' | 'hidden' };
4141

42-
export type Polling = 'raf' | 'mutation' | number;
42+
export type Polling = 'raf' | number;
4343
export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling };
4444

4545
export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle';

test/waittask.spec.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ describe('Frame.waitForFunction', function() {
5252
}, {}, {polling});
5353
expect(timeDelta).not.toBeLessThan(polling);
5454
});
55-
it('should poll on mutation', async({page, server}) => {
56-
let success = false;
57-
const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {}, {polling: 'mutation'})
58-
.then(() => success = true);
59-
await page.evaluate(() => window.__FOO = 'hit');
60-
expect(success).toBe(false);
61-
await page.evaluate(() => document.body.appendChild(document.createElement('div')));
62-
await watchdog;
55+
it('should throw on polling:mutation', async({page, server}) => {
56+
const error = await page.waitForFunction(() => true, {}, {polling: 'mutation'}).catch(e => e);
57+
expect(error.message).toBe('Unknown polling option: mutation');
6358
});
6459
it('should poll on raf', async({page, server}) => {
6560
const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {}, {polling: 'raf'});

0 commit comments

Comments
 (0)