-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
test(bidi): Update beforeunload tests to avoid hangs with bidi #34281
base: main
Are you sure you want to change the base?
test(bidi): Update beforeunload tests to avoid hangs with bidi #34281
Conversation
Note that on Firefox + BiDi the tests also fail at the moment because the URL is missing from the corresponding navigationStarted event, which is tracked at https://bugzilla.mozilla.org/show_bug.cgi?id=1908952 We should workaround this by modifying the _onNavigationStarted handler on playwright's side, but this can be handled in a different PR. playwright/packages/playwright-core/src/server/bidi/bidiPage.ts Lines 183 to 190 in 13bdd3c
|
This comment has been minimized.
This comment has been minimized.
According to the documentation, "If runBeforeUnload is true the method will run unload handlers, but will not wait for the page to close.". So this behavior seems to be intentional. Also the first test ('should run beforeunload if asked for @smoke') passes when I run it locally. I'd rather try to align Bidi behavior with the existing implementation or at least understand why it is different. |
Thanks for taking a look!
Did you remove it from the timeout expectations? For me it fails first because of the And if I fix that, then it hangs. |
Yeah, blocking diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts
index cf0662738..61d5dd20b 100644
--- a/packages/playwright-core/src/server/bidi/bidiPage.ts
+++ b/packages/playwright-core/src/server/bidi/bidiPage.ts
@@ -384,10 +384,12 @@ export class BidiPage implements PageDelegate {
}
async closePage(runBeforeUnload: boolean): Promise<void> {
- await this._session.send('browsingContext.close', {
+ const promise = this._session.send('browsingContext.close', {
context: this._session.sessionId,
promptUnload: runBeforeUnload,
});
+ if (!runBeforeUnload)
+ await promise;
}
async setBackgroundColor(color?: { r: number; g: number; b: number; a: number; }): Promise<void> {
I'm running without Update: fails on Linux:
FYI, you can run with |
I will open an issue on the BiDi spec to discuss this, but having a consistent behavior for the command (ie always waiting for the tab to close) might be an argument in favor of the current approach. If consumers want to cancel the navigation, arguably they can just not wait on the command.
Not sure what happens. I am on mac as well. In my case, I always get first the error with params.url, so it needs to be fixed to get the timeout. I will update the PR with fixes for both issues, I can't really see how the current test would not timeout with BiDi (once the params.url issue is fixed, that is). So to be clear, running the
|
To summarize, I think the test failures highlight two issues in Bidi:
If those issues are resolved, both tests should start passing. |
Sorry, I posted my response before seeing yours, let me see what happens if url problem is resolved. |
Filed the spec issue, I'll leave it up to you if you prefer to wait for a decision there. It feels to me like both approaches can make sense, so it seems reasonable to handle it on the Playwright side, but that's not for me to decide :) About the current bug for the missing |
9917afd
to
8778e02
Compare
// url is missing from navigationStarted events on Firefox when the | ||
// navigation is interrupted by a beforeunload prompt. | ||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1908952 | ||
if (!params.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would just mask the problem and potentially other issues elsewhere. Let's revert this and keep the test failing (it stops timing out with the other fix in this PR, right?). Our primary objective is to ensure the logic functions correctly when the protocol implementation provides the property, rather than working around the current issues in the Bidi protocol.
Thanks! I'd rather have the problem resolved in the spec. The problem with the workaround on playwright end is that we have to also catch potential errors in |
// Otherwise a before unload prompt might be displayed and should be handled | ||
// by the caller. | ||
// See NOTE on https://playwright.dev/docs/api/class-page#page-close | ||
if (!runBeforeUnload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to catch potential exceptions if not awaiting to avoid unhandled promise rejection.
Test results for "tests 1"6 flaky37569 passed, 648 skipped Merge workflow run. |
The WebDriver BiDi browsingContext.close command will only resolve when the context closes.
Some beforeunload tests are awaiting on browsingContext.close before dismissing the beforeunload prompt and therefore will deadlock and timeout.