fix(chromium): prevent TargetClosedException on main-frame cross-process navigation - #41424
fix(chromium): prevent TargetClosedException on main-frame cross-process navigation#41424karimnabli wants to merge 2 commits into
Conversation
…ess navigation (microsoft#41348) Signed-off-by: Karim Nabli <karim.nabli.ie@gmail.com>
|
@microsoft-github-policy-service agree |
|
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, @pavelfeldman @dgozman |
|
Hi, @pavelfeldman @dgozman @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. |
Signed-off-by: Karim Nabli <karim.nabli.ie@gmail.com>
1c03e8f to
8a6a13d
Compare
|
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. |
|
@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. |
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.