fix: allow disposing ElementHandles multiple times (#29953)
Fixes https://github.com/microsoft/playwright/issues/29945
This commit is contained in:
parent
3e78426acc
commit
5bc6ca6345
|
@ -19,6 +19,7 @@ import { ChannelOwner } from './channelOwner';
|
||||||
import { parseSerializedValue, serializeValue } from '../protocol/serializers';
|
import { parseSerializedValue, serializeValue } from '../protocol/serializers';
|
||||||
import type * as api from '../../types/types';
|
import type * as api from '../../types/types';
|
||||||
import type * as structs from '../../types/structs';
|
import type * as structs from '../../types/structs';
|
||||||
|
import { isTargetClosedError } from './errors';
|
||||||
|
|
||||||
export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> implements api.JSHandle {
|
export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> implements api.JSHandle {
|
||||||
private _preview: string;
|
private _preview: string;
|
||||||
|
@ -68,7 +69,13 @@ export class JSHandle<T = any> extends ChannelOwner<channels.JSHandleChannel> im
|
||||||
}
|
}
|
||||||
|
|
||||||
async dispose() {
|
async dispose() {
|
||||||
return await this._channel.dispose();
|
try {
|
||||||
|
await this._channel.dispose();
|
||||||
|
} catch (e) {
|
||||||
|
if (isTargetClosedError(e))
|
||||||
|
return;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _objectCount() {
|
async _objectCount() {
|
||||||
|
|
|
@ -85,3 +85,12 @@ it('should focus a button', async ({ page, server }) => {
|
||||||
await button.focus();
|
await button.focus();
|
||||||
expect(await button.evaluate(button => document.activeElement === button)).toBe(true);
|
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();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue