Skip to content

chore(bidi): guard against race condition in utility world creation#41789

Merged
yury-s merged 1 commit into
microsoft:mainfrom
hbenl:utility-world-race-condition
Jul 16, 2026
Merged

chore(bidi): guard against race condition in utility world creation#41789
yury-s merged 1 commit into
microsoft:mainfrom
hbenl:utility-world-race-condition

Conversation

@hbenl

@hbenl hbenl commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

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.

@yury-s

yury-s commented Jul 16, 2026

Copy link
Copy Markdown
Member

However, it is not guaranteed that they are received in the same order that they were requested in

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.

frame.contextCreated('utility', utilityContext);
this._contextIdToContext.set(result.realm, utilityContext);
} catch (error) {
debugLogger.log('error', error);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can probably just swallow it, protocol logs should be enough for debugging

@yury-s yury-s merged commit 48a2efe into microsoft:main Jul 16, 2026
4 checks passed
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.

2 participants