fix: allow disposing ElementHandles multiple times (#29953)
Fixes https://github.com/microsoft/playwright/issues/29945
This commit is contained in:
Родитель
3e78426acc
Коммит
5bc6ca6345
|
@ -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();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче