Skip to content

fix(chromium): prevent TargetClosedException on main-frame cross-process navigation#41424

Open
karimnabli wants to merge 1 commit into
microsoft:mainfrom
karimnabli:fix/41348-chromium-cross-origin-race
Open

fix(chromium): prevent TargetClosedException on main-frame cross-process navigation#41424
karimnabli wants to merge 1 commit into
microsoft:mainfrom
karimnabli:fix/41348-chromium-cross-origin-race

Conversation

@karimnabli

Copy link
Copy Markdown

Fixes #41348

Root Cause

In crPage.ts, the _onDetachedFromTarget method assumes that a detached target implies either a swap or a true detach. However, Azure OAuth introduces a third case: a main-frame cross-process navigation.

Due to the microtask delay in Page.enable, the session mapping changes, and Playwright incorrectly calls frameDetached, throwing a TargetClosedException immediately after the "Stay signed in?" click.

Fix

Added a guard in _onDetachedFromTarget to verify if the session currently mapped to the targetId is still the childFrameSession that triggered the detachment. If a new session has taken over (indicating a cross-process navigation), we skip the frameDetached call and simply dispose of the old session.

Test

Added a regression test in tests/library/chromium/oopif.spec.ts that simulates a cross-origin redirect after a form submission to ensure the page survives the transition.

…ess navigation (microsoft#41348)

Signed-off-by: Karim Nabli <karim.nabli.ie@gmail.com>
@karimnabli

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@karimnabli

karimnabli commented Jun 23, 2026

Copy link
Copy Markdown
Author

@pavelfeldman @dgozman

I’ve implemented a fix for #41348

Root cause:
In crPage.ts, _onDetachedFromTarget assumes a detached target is either a swap or a true detach. However, Azure OAuth introduces a third case: a main-frame cross-process navigation. Due to the microtask delay in Page.enable, the session mapping changes and Playwright incorrectly calls frameDetached, leading to a TargetClosedException right after the "Stay signed in?" click.

Fix:
Added a guard in _onDetachedFromTarget to verify whether the session currently mapped to the targetId is still the childFrameSession that triggered the detachment. If a new session has taken over (cross-process navigation), the frameDetached call is skipped and the old session is simply disposed.

Test:
Added a regression test in tests/library/chromium/oopif.spec.ts that simulates a cross-origin redirect after form submission to ensure the page survives the transition.

Could you please review whether this approach aligns with the expected handling of cross-process navigations?

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]: TargetClosedException thrown after clicking "Yes" on MS OAuth prompt in 1.60 (Regression from 1.58)

1 participant