chore: don't leak from waitFor (#22465)

Fixes https://github.com/microsoft/playwright/issues/22458
This commit is contained in:
Pavel Feldman 2023-04-18 14:11:46 -04:00 committed by GitHub
parent 4e9faba34d
commit d45efe881f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 1 deletions

1
package-lock.json generated
View File

@ -6199,6 +6199,7 @@
}
},
"packages/playwright-ct-core": {
"name": "@playwright/experimental-ct-core",
"version": "1.33.0-next",
"license": "Apache-2.0",
"dependencies": {

View File

@ -815,6 +815,10 @@ export class Frame extends SdkObject {
result.dispose();
return continuePolling;
}
if (options.omitReturnValue) {
result.dispose();
return null;
}
const element = state === 'attached' || state === 'visible' ? await result.evaluateHandle(r => r.element) : null;
result.dispose();
if (!element)

View File

@ -25,7 +25,7 @@ export type StrictOptions = {
export type QueryOnSelectorOptions = StrictOptions & TimeoutOptions;
export type WaitForElementOptions = TimeoutOptions & StrictOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' };
export type WaitForElementOptions = TimeoutOptions & StrictOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' } & { omitReturnValue?: boolean };
export type WaitForFunctionOptions = TimeoutOptions & { pollingInterval?: number };

View File

@ -149,3 +149,33 @@ test('expect should not leak', async ({ page, mode, browserName, toImpl }) => {
expect(counts.main + counts.utility).toBeLessThan(25);
}
});
test('waitFor should not leak', async ({ page, mode, browserName, toImpl }) => {
test.skip(mode !== 'default');
await page.setContent(`
<button>static button 1</button>
<button>static button 2</button>
<div id="buttons"></div>
`);
for (let i = 0; i < 25; ++i) {
await page.evaluate(i => {
const element = document.createElement('button');
element.textContent = 'dynamic ' + i;
document.getElementById('buttons').appendChild(element);
}, i);
await page.locator('#buttons > button').waitFor();
await page.evaluate(() => {
document.getElementById('buttons').textContent = '';
});
}
expect(leakedJSHandles()).toBeFalsy();
if (browserName === 'chromium') {
const counts = await objectCounts(toImpl(page), 'HTMLButtonElement');
expect(counts.main + counts.utility).toBeGreaterThanOrEqual(2);
expect(counts.main + counts.utility).toBeLessThan(25);
}
});