Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(dispose): do not await inner handle dispose (#1230)
Dmitry Gozman3bedc60b2bc4
diff --git a/src/chromium/crPage.ts b/src/chromium/crPage.tsindex 0014db703a..de04ad6874 100644--- a/src/chromium/crPage.ts+++ b/src/chromium/crPage.ts@@ -483,7 +483,7 @@ export class CRPage implements PageDelegate {});const frameId = nodeInfo && typeof nodeInfo.node.frameId === 'string' ?nodeInfo.node.frameId : null;- await documentElement.dispose();+ documentElement.dispose();return frameId;}diff --git a/src/chromium/crProtocolHelper.ts b/src/chromium/crProtocolHelper.tsindex 4fbef2d7e7..d49d312364 100644--- a/src/chromium/crProtocolHelper.ts+++ b/src/chromium/crProtocolHelper.ts@@ -15,7 +15,7 @@* limitations under the License.*/-import { assert, debugError } from '../helper';+import { assert } from '../helper';import { CRSession } from './crConnection';import { Protocol } from './protocol';import * as platform from '../platform';@@ -58,11 +58,7 @@ export function valueFromRemoteObject(remoteObject: Protocol.Runtime.RemoteObjecexport async function releaseObject(client: CRSession, remoteObject: Protocol.Runtime.RemoteObject) {if (!remoteObject.objectId)return;- await client.send('Runtime.releaseObject', {objectId: remoteObject.objectId}).catch(error => {- // Exceptions might happen in case of a page been navigated or closed.- // Swallow these since they are harmless and we don't leak anything in this case.- debugError(error);- });+ await client.send('Runtime.releaseObject', {objectId: remoteObject.objectId}).catch(error => {});}export async function readProtocolStream(client: CRSession, handle: string, path: string | null): Promise<platform.BufferType> {diff --git a/src/dom.ts b/src/dom.tsindex 3e415a8d4e..e0c17abc73 100644--- a/src/dom.ts+++ b/src/dom.ts@@ -67,7 +67,7 @@ export class FrameExecutionContext extends js.ExecutionContext {try {result = await this._delegate.evaluate(this, returnByValue, pageFunction, ...adopted);} finally {- await Promise.all(toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose())));+ toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose()));}return result;}@@ -105,7 +105,7 @@ export class FrameExecutionContext extends js.ExecutionContext {await this._injected(), selector, scope);if (!handle.asElement())- await handle.dispose();+ handle.dispose();return handle.asElement() as ElementHandle<Element>;}@@ -120,14 +120,14 @@ export class FrameExecutionContext extends js.ExecutionContext {async _$$(selector: string, scope?: ElementHandle): Promise<ElementHandle<Element>[]> {const arrayHandle = await this._$array(selector, scope);const properties = await arrayHandle.getProperties();- await arrayHandle.dispose();+ arrayHandle.dispose();const result: ElementHandle<Element>[] = [];for (const property of properties.values()) {const elementHandle = property.asElement() as ElementHandle<Element>;if (elementHandle)result.push(elementHandle);else- await property.dispose();+ property.dispose();}return result;}@@ -378,14 +378,14 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {if (!elementHandle)throw new Error(`Error: failed to find element matching selector "${selector}"`);const result = await elementHandle.evaluate(pageFunction, ...args as any);- await elementHandle.dispose();+ elementHandle.dispose();return result;}$$eval: types.$$Eval = async (selector, pageFunction, ...args) => {const arrayHandle = await this._context._$array(selector, this);const result = await arrayHandle.evaluate(pageFunction, ...args as any);- await arrayHandle.dispose();+ arrayHandle.dispose();return result;}diff --git a/src/firefox/ffExecutionContext.ts b/src/firefox/ffExecutionContext.tsindex 24c9e28b92..c7db7ca2fa 100644--- a/src/firefox/ffExecutionContext.ts+++ b/src/firefox/ffExecutionContext.ts@@ -15,7 +15,7 @@* limitations under the License.*/-import {helper, debugError} from '../helper';+import { helper } from '../helper';import * as js from '../javascript';import { FFSession } from './ffConnection';import { Protocol } from './protocol';@@ -122,11 +122,7 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {await this._session.send('Runtime.disposeObject', {executionContextId: this._executionContextId,objectId: handle._remoteObject.objectId,- }).catch(error => {- // Exceptions might happen in case of a page been navigated or closed.- // Swallow these since they are harmless and we don't leak anything in this case.- debugError(error);- });+ }).catch(error => {});}async handleJSONValue<T>(handle: js.JSHandle<T>): Promise<T> {diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.tsindex ea9a271f09..d2882997b1 100644--- a/src/firefox/ffPage.ts+++ b/src/firefox/ffPage.ts@@ -447,7 +447,7 @@ export class FFPage implements PageDelegate {return { handle, frame };}));const result = items.find(item => item.frame === frame);- await Promise.all(items.map(item => item === result ? Promise.resolve() : item.handle.dispose()));+ items.map(item => item === result ? Promise.resolve() : item.handle.dispose());if (!result)throw new Error('Frame has been detached.');return result.handle;diff --git a/src/frames.ts b/src/frames.tsindex 99918b2812..117e9b5939 100644--- a/src/frames.ts+++ b/src/frames.ts@@ -549,7 +549,7 @@ export class Frame {const handle = await utilityContext._$(selector);if (handle && handle._context !== mainContext) {const adopted = this._page._delegate.adoptElementHandle(handle, mainContext);- await handle.dispose();+ handle.dispose();return adopted;}return handle;@@ -561,7 +561,7 @@ export class Frame {const mainContext = await this._mainContext();if (handle && handle._context !== mainContext) {const adopted = this._page._delegate.adoptElementHandle(handle, mainContext);- await handle.dispose();+ handle.dispose();return adopted;}return handle;@@ -577,7 +577,7 @@ export class Frame {if (!elementHandle)throw new Error(`Error: failed to find element matching selector "${selector}"`);const result = await elementHandle.evaluate(pageFunction, ...args as any);- await elementHandle.dispose();+ elementHandle.dispose();return result;}@@ -585,7 +585,7 @@ export class Frame {const context = await this._mainContext();const arrayHandle = await context._$array(selector);const result = await arrayHandle.evaluate(pageFunction, ...args as any);- await arrayHandle.dispose();+ arrayHandle.dispose();return result;}@@ -782,63 +782,63 @@ export class Frame {async click(selector: string, options?: dom.ClickOptions & types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.click(options);- await handle.dispose();+ handle.dispose();}async dblclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.dblclick(options);- await handle.dispose();+ handle.dispose();}async tripleclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.tripleclick(options);- await handle.dispose();+ handle.dispose();}async fill(selector: string, value: string, options?: types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.fill(value);- await handle.dispose();+ handle.dispose();}async focus(selector: string, options?: types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.focus();- await handle.dispose();+ handle.dispose();}async hover(selector: string, options?: dom.PointerActionOptions & types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.hover(options);- await handle.dispose();+ handle.dispose();}async select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions): Promise<string[]> {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);const values = Array.isArray(value) ? value : [value];const result = await handle.select(...values);- await handle.dispose();+ handle.dispose();return result;}async type(selector: string, text: string, options?: { delay?: number } & types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.type(text, options);- await handle.dispose();+ handle.dispose();}async check(selector: string, options?: types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.check(options);- await handle.dispose();+ handle.dispose();}async uncheck(selector: string, options?: types.WaitForOptions) {const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);await handle.uncheck(options);- await handle.dispose();+ handle.dispose();}async waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options: types.WaitForFunctionOptions & { visibility?: types.Visibility } = {}, ...args: any[]): Promise<js.JSHandle | null> {@@ -879,7 +879,7 @@ export class Frame {const task = dom.waitForSelectorTask(selector, visibility, timeout);const result = await this._scheduleRerunnableTask(task, 'utility', timeout, `selector "${selectorToString(selector, visibility)}"`);if (!result.asElement()) {- await result.dispose();+ result.dispose();return null;}return result.asElement() as dom.ElementHandle<Element>;@@ -993,7 +993,7 @@ class RerunnableTask {if (this._terminated || runCount !== this._runCount) {if (success)- await success.dispose();+ success.dispose();return;}@@ -1001,7 +1001,7 @@ class RerunnableTask {// If execution context has been already destroyed, `context.evaluate` will// throw an error - ignore this predicate run altogether.if (!error && await context.evaluate(s => !s, success).catch(e => true)) {- await success!.dispose();+ success!.dispose();return;}diff --git a/src/javascript.ts b/src/javascript.tsindex 0b25f68607..73add31a0b 100644--- a/src/javascript.ts+++ b/src/javascript.ts@@ -75,7 +75,7 @@ export class JSHandle<T = any> {}, propertyName);const properties = await objectHandle.getProperties();const result = properties.get(propertyName) || null;- await objectHandle.dispose();+ objectHandle.dispose();return result;}diff --git a/src/page.ts b/src/page.tsindex d56045e2ce..9ed872f01e 100644--- a/src/page.ts+++ b/src/page.ts@@ -187,7 +187,7 @@ export class Page extends platform.EventEmitter {async _onFileChooserOpened(handle: dom.ElementHandle) {const multiple = await handle.evaluate(element => !!(element as HTMLInputElement).multiple);if (!this.listenerCount(Events.Page.FileChooser)) {- await handle.dispose();+ handle.dispose();return;}const fileChooser: FileChooser = { element: handle, multiple };diff --git a/src/webkit/wkPage.ts b/src/webkit/wkPage.tsindex de923b1881..95c4e0d2f2 100644--- a/src/webkit/wkPage.ts+++ b/src/webkit/wkPage.ts@@ -630,7 +630,7 @@ export class WKPage implements PageDelegate {return { handle, frame };}));const result = items.find(item => item.frame === frame);- await Promise.all(items.map(item => item === result ? Promise.resolve() : item.handle.dispose()));+ items.map(item => item === result ? Promise.resolve() : item.handle.dispose());if (!result)throw new Error('Frame has been detached.');return result.handle;diff --git a/src/webkit/wkProtocolHelper.ts b/src/webkit/wkProtocolHelper.tsindex 8d8bcee838..ff19da907b 100644--- a/src/webkit/wkProtocolHelper.ts+++ b/src/webkit/wkProtocolHelper.ts@@ -15,7 +15,7 @@* limitations under the License.*/-import { assert, debugError } from '../helper';+import { assert } from '../helper';import { WKSession } from './wkConnection';import { Protocol } from './protocol';@@ -46,10 +46,6 @@ export function valueFromRemoteObject(remoteObject: Protocol.Runtime.RemoteObjecexport async function releaseObject(client: WKSession, remoteObject: Protocol.Runtime.RemoteObject) {if (!remoteObject.objectId)return;- await client.send('Runtime.releaseObject', {objectId: remoteObject.objectId}).catch(error => {- // Exceptions might happen in case of a page been navigated or closed.- // Swallow these since they are harmless and we don't leak anything in this case.- debugError(error);- });+ await client.send('Runtime.releaseObject', {objectId: remoteObject.objectId}).catch(error => {});}