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

Conversation

pmmmwh
Copy link
Contributor

@pmmmwh pmmmwh commented Feb 15, 2022

What kind of change does this PR introduce?

bug fix

Did you add tests for your changes?

Yes

No, but can add if deemed necessary

If relevant, did you update the documentation?

No

Summary

Fixes #7814

Functions exposed via page.exposeFunction are not unbind when a frame is detached, which in turn causes the error regarding missing execution context being raised.

executionContext(): Promise<ExecutionContext> {
if (this._detached)
throw new Error(
`Execution context is not available in detached frame "${this._frame.url()}" (are you trying to evaluate?)`
);
return this._contextPromise;
}

This PR adds _detached as a criterion to _hasContext, indicating there is no context available, causing _onBindCalled to exit early. An alternative solution could be to remove all Runtime.bindingCalled listeners on the client when detaching, which will stop events from firing completely.

this._client.on('Runtime.bindingCalled', (event) =>
this._onBindingCalled(event)
);

Does this PR introduce a breaking change?

No

Other information

First started happening in 11.0.0, still reproducible in the latest release.
Tested on Node.js 14.x and 16.x.

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 15, 2022

Would it be much more difficult to implement the alternative solution? Also, I think it'd be really great to have a test for this.

@pmmmwh pmmmwh changed the title fix: ensure dom binding is not called after detatch fix: ensure dom binding is not called after detach Feb 17, 2022
test/page.spec.ts Outdated Show resolved Hide resolved
@OrKoN
Copy link
Collaborator

OrKoN commented Feb 17, 2022

Thanks a lot. Looks good, I just added a suggestion to fix the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unhandled promise rejection in case of binded function called with detached frame
2 participants