chore(bidi): guard against race condition in utility world creation#41789
Merged
Conversation
Member
Oh, wow, good to know. I think in other protocols we can assume that at least within same command and same target the responses would come at the same order. |
yury-s
approved these changes
Jul 16, 2026
| frame.contextCreated('utility', utilityContext); | ||
| this._contextIdToContext.set(result.realm, utilityContext); | ||
| } catch (error) { | ||
| debugLogger.log('error', error); |
Member
There was a problem hiding this comment.
nit: we can probably just swallow it, protocol logs should be enough for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During initial navigations, browsers may quickly create multiple javascript execution contexts with different origins for the same frame. Playwright will request a utility world for each of them and use the last one that was received from the browser. However, it is not guaranteed that they are received in the same order that they were requested in, so Playwright may end up using a utility world corresponding to an earlier main world that is then quickly destroyed.
This PR guards against this race condition by checking if the main world has changed since the utility world was requested.
Fixes the flaky test "top level 'Partitioned;' cookie and same origin iframe" in
library/browsercontext-cookies-third-party.spec.ts.