Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(binding): catch binding resolution against the closed page (#4583)

Pavel Feldman7e30669eb01e
diff --git a/src/client/page.ts b/src/client/page.ts
index 9f1533c400..98af7eb56c 100644
--- a/src/client/page.ts
+++ b/src/client/page.ts
@@ -649,9 +649,9 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel, chann
result = await func(source, JSHandle.from(this._initializer.handle));
else
result = await func(source, ...this._initializer.args!.map(parseResult));
- this._channel.resolve({ result: serializeArgument(result) });
+ this._channel.resolve({ result: serializeArgument(result) }).catch(() => {});
} catch (e) {
- this._channel.reject({ error: serializeError(e) });
+ this._channel.reject({ error: serializeError(e) }).catch(() => {});
}
}
}
diff --git a/test/page-expose-function.spec.ts b/test/page-expose-function.spec.ts
index 5be48dc77b..ff369c0d39 100644
--- a/test/page-expose-function.spec.ts
+++ b/test/page-expose-function.spec.ts
@@ -222,3 +222,12 @@ it('exposeBindingHandle should throw for multiple arguments', async ({page}) =>
}).catch(e => e);
expect(error.message).toContain('exposeBindingHandle supports a single argument, 2 received');
});
+
+it('should not result in unhandled rejection', async ({page}) => {
+ await page.exposeFunction('foo', async () => {
+ await page.close();
+ });
+ await page.evaluate(() => {
+ (window as any).foo();
+ });
+});