Uh oh!
There was an error while loading. Please reload this page.
fix(chromium): prevent TargetClosedException on main-frame cross-process navigation - #41424
Conversation
…ess navigation (microsoft#41348) Signed-off-by: Karim Nabli <karim.nabli.ie@gmail.com>
Karim Nabli (karimnabli)
commented
Jun 23, 2026
@microsoft-github-policy-service agree |
Pavel Feldman (@pavelfeldman)Dmitry Gozman (@dgozman) I’ve implemented a fix for #41348 Root cause: Fix: Test: Could you please review whether this approach aligns with the expected handling of cross-process navigations? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Test results for "MCP"3 failed 7458 passed, 1132 skipped Merge workflow run. |
Test results for "tests 1"2 failed 7 flaky49170 passed, 1163 skipped Merge workflow run. |
Hi, Pavel Feldman (@pavelfeldman)Dmitry Gozman (@dgozman) |
Hi, Pavel Feldman (@pavelfeldman)Dmitry Gozman (@dgozman)Simon Knott (@Skn0tt) – I wanted to flag that the failing MCP test ( Evidence:
My PR changes:
The MCP job failure should not block this PR. If needed, I'm happy to see if this test flakiness can be addressed in a separate issue. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Karim Nabli <karim.nabli.ie@gmail.com>
1c03e8f to
8a6a13dCompareDmitry Gozman (dgozman)
commented
Jul 22, 2026
I tried to run pretty much your exact test on the bots, without a fix, to see what's going wrong: #41930. Turns out, it passes on every bot. Now I am not sure we are fixing the right problem at all. We need some easy-ish repro that we can turn into a test to make sure we are fixing the actual issue. |
Karim Nabli (karimnabli)
commented
Jul 27, 2026
Dmitry Gozman (@dgozman)
Despite these exhaustive efforts, the test passes locally even without the fix. The conclusion is that the Playwright test harness environment (due to Node.js event loop timing and OS-level TCP stack differences) fundamentally smooths over this specific microtask race window. However, the C# reproduction in the issue description #41348 reliably triggers the TargetClosedException in Playwright 1.60.0 and succeeds with this fix. That script serves as definitive proof that the bug exists and the fix resolves it. I will not make further code changes to the test. The fix itself is a defensive guard that prevents dispose() from unconditionally clobbering the _sessions map if a cross-process navigation has already taken over the targetId. This is objectively safer code, regardless of the test harness's ability to reproduce the timing. I understand if this is not sufficient for merging without a failing test. Unless you have a specific insight on how to force this exact CDP timing window within the Playwright test environment, I believe the defensive nature of the fix and the verified real-world reproduction could be considered as sufficient. |
Pavel Feldman (pavelfeldman)
commented
Jul 30, 2026
I'll close this as per #41424 (comment) |
Pavel Feldman (@pavelfeldman)Dmitry Gozman (@dgozman) We have a critical Azure OAuth login flow that:
This is not a theoretical edge case. It is actively blocking our CI/CD pipeline and preventing us from running automated regression tests for our authentication flow. The proposed fix was a simple, defensive guard that prevents Since the PR was closed due to the test harness's inability to reproduce this specific microtask race window (despite exhaustive attempts with raw TCP servers and artificial delays), I am asking for guidance on how to proceed:
|
Fixes#41348
Root Cause
In
crPage.ts, the_onDetachedFromTargetmethod 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 callsframeDetached, throwing aTargetClosedExceptionimmediately after the "Stay signed in?" click.Fix
Added a guard in
_onDetachedFromTargetto verify if the session currently mapped to thetargetIdis still thechildFrameSessionthat triggered the detachment. If a new session has taken over (indicating a cross-process navigation), we skip theframeDetachedcall and simply dispose of the old session.Test
Added a regression test in
tests/library/chromium/oopif.spec.tsthat simulates a cross-origin redirect after a form submission to ensure the page survives the transition.