fix(electron): close pages from the main process to avoid Target.closeTarget hang#41695
Open
yury-s wants to merge 1 commit into
Open
fix(electron): close pages from the main process to avoid Target.closeTarget hang#41695yury-s wants to merge 1 commit into
yury-s wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dgozman
reviewed
Jul 8, 2026
13d604f to
7df6703
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…eTarget hang page.close() sends CDP Target.closeTarget and waits for the browser-level Target.detachedFromTarget event to resolve. On Electron, when the close races a navigation that is being committed, Electron acks Target.closeTarget with success but silently drops the actual close, so the target is never destroyed and page.close() hangs forever (Electron has no unload watchdog to recover, unlike Chrome). Close the page from the main process instead via a per-page custom close handler that calls webContents.close(). This is not subject to the CDP/ navigation race, and webContents.close() (without waitForBeforeUnload) closes without running beforeunload, matching page.close(runBeforeUnload: false) semantics.
7df6703 to
f17a470
Compare
Contributor
Test results for "MCP"2 failed 7733 passed, 1248 skipped Merge workflow run. |
Contributor
Test results for "tests 1"49516 passed, 1161 skipped Merge workflow run. |
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.
Summary
page.close()sends CDPTarget.closeTargetand resolves only on the browser-levelTarget.detachedFromTargetevent. On Electron, when the close races a navigation that is being committed, Electron acksTarget.closeTargetwithsuccessbut silently drops the actual close, so the target is never destroyed andpage.close()hangs forever (Electron has no unload watchdog to recover, unlike Chrome). This surfaced as flaky Electron teardown timeouts in CI (e.g.page-autowaiting-no-hang.spec.ts"assigning location to about:blank").webContents.close(), which is not subject to the CDP/navigation race.webContents.close()(withoutwaitForBeforeUnload) closes without runningbeforeunload, matchingpage.close(runBeforeUnload: false)force-close semantics.