Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure dom binding is not called after detach #8024

Merged
merged 4 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/common/DOMWorld.ts
Expand Up @@ -111,9 +111,8 @@ export class DOMWorld {
this._frame = frame;
this._timeoutSettings = timeoutSettings;
this._setContext(null);
this._client.on('Runtime.bindingCalled', (event) =>
this._onBindingCalled(event)
);
this._onBindingCalled = this._onBindingCalled.bind(this);
this._client.on('Runtime.bindingCalled', this._onBindingCalled);
}

frame(): Frame {
Expand Down Expand Up @@ -144,6 +143,7 @@ export class DOMWorld {

_detach(): void {
this._detached = true;
this._client.off('Runtime.bindingCalled', this._onBindingCalled);
for (const waitTask of this._waitTasks)
waitTask.terminate(
new Error('waitForFunction failed: frame got detached.')
Expand Down
16 changes: 16 additions & 0 deletions test/page.spec.ts
Expand Up @@ -1035,6 +1035,22 @@ describe('Page', function () {
});
expect(result).toBe(15);
});
it('should not throw when frames detach', async () => {
const { page, server } = getTestState();

await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
await page.exposeFunction('compute', function (a, b) {
return Promise.resolve(a * b);
});
await utils.detachFrame(page, 'frame1');

await expect(
page.evaluate(async function () {
return await globalThis.compute(3, 5);
})
).resolves.toEqual(15);
});
it('should work with complex objects', async () => {
const { page } = getTestState();

Expand Down