fix: allow disposing ElementHandles multiple times (#29953)

Fixes https://github.com/microsoft/playwright/issues/29945
This commit is contained in:
Max Schmitt 2024-03-15 16:26:56 +01:00 коммит произвёл GitHub
Родитель 3e78426acc
Коммит 5bc6ca6345
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -19,6 +19,7 @@ import { ChannelOwner } from './channelOwner';
import { parseSerializedValue, serializeValue } from '../protocol/serializers';
import type * as api from '../../types/types';
import type * as structs from '../../types/structs';
import { isTargetClosedError } from './errors';
export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> implements api.JSHandle {
private _preview: string;
@ -68,7 +69,13 @@ export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> im
}
async dispose() {
return await this._channel.dispose();
try {
await this._channel.dispose();
} catch (e) {
if (isTargetClosedError(e))
return;
throw e;
}
}
async _objectCount() {

Просмотреть файл

@ -85,3 +85,12 @@ it('should focus a button', async ({ page, server }) => {
await button.focus();
expect(await button.evaluate(button => document.activeElement === button)).toBe(true);
});
it('should allow disposing twice', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29945' });
await page.setContent('<section>39</section>');
const element = await page.$('section');
expect(element).toBeTruthy();
await element.dispose();
await element.dispose();
});