-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing child window hangs main window #20086
Comments
@sofianguy This is actually a blocker for stable (for some of us at least) as pop-outs (child windows) are common use cases. |
Details of this error: (I tested it on v6.0.11) For reproduce use this code: win = new BrowserWindow({
width: 1200,
height: 700,
webPreferences: {
nativeWindowOpen: true,
nodeIntegration: false,
sandbox: true,
preload: require.resolve('./preload'), // required for reproduce the error
},
frame: false,
})
win.webContents.openDevTools({
mode : 'undocked',
activate: true,
}) preload.js // may only contain this line for reproduce the error
const {remote} = require('electron') Run the app and run in the console: var win = window.open('about:blank', '', 'width=600,height=400')
win.document.write('Some text')
win.close()
// after this main window will hung, and dev tools will partly not work (you cannot run another console command) Temporary solution (hack): var win = window.open('about:blank', '', 'width=600,height=400')
// fix electron bug with close about:blank windows
const winClose = win.close.bind(window)
win.close = () => {
if (window.minimize) {
window.minimize()
}
window.location.href = 'http://0.0.0.0/' // if you change window url and wait, you can close window without error
setTimeout(() => winClose(), 2000)
} |
Improved solution of bypass the error:
preload.js
|
I've investigated the issue and found the root cause. The electron/lib/renderer/api/remote.js Lines 20 to 23 in db91673
It's emitted when the JS context is being destroyed: electron/shell/renderer/atom_renderer_client.cc Lines 154 to 164 in db91673
The problem is that electron/shell/renderer/api/atom_api_renderer_ipc.cc Lines 191 to 200 in db91673
@nornagon This regressed when |
This bug is platform independent. |
@miniak what version are you testing with? I have a fix for 6-0-x in #20547. When I implement a similar fix in 7-0-x/master, I hit a V8 error that I haven't been able to track down yet. Ultimately, the problem is that we allow Chrome to create a WebContents and immediately kill it — the long term fix is an API change. But I'm still hoping to get a short term fix up this week, if possible. |
This is a repro on master. But we need to fix it in 6 and 7 as well |
@loc when I tried using an async IPC instead, I am not receiving it in the main process, which is expected as the mojo interface is disconnected. Even if we fix the sync version, the problem would be that the rpc-server in main won't get a notification that the context is released and memory would leak |
@loc which should be ok since: electron/lib/renderer/api/remote.js Lines 16 to 23 in 825e671
|
Curious how this is not a blocker for stable build? Unable to upgrade from v5 due to prevalence of this issue v6 onwards |
https://github.com/zarubond/electron-quick-start/tree/child_hang does not reproduce the error in the currently-supported versions of Electron. Tested with
Unless there's a critical security issue that would merit patching an unsupported version, this won't be fixed in 6. In any case, the better solution would be for all applications still running on Electron 6 to upgrade. |
It does reproduce with version
and the only one where closing a child window works smoothly is the |
Preflight Checklist
Issue Details
I have enabled nativeWindowOpen and nodeIntegrationInSubFrames for main window, and I have a preload script which required a remote from electron. Which this configuration I open a child window and then I close it. The main window render process hangs for ever so I have to restart whole app. Here is and example app https://github.com/zarubond/electron-quick-start/tree/child_hang
6.0.7, 7.0.0-beta3
Windows, Linux, MacOS
5.0.10
Expected Behavior
Closing child window should not hang main window for ever
Actual Behavior
Main window hangs after closing child window.
To Reproduce
Open child window and then close it
Screenshots
Additional Information
The text was updated successfully, but these errors were encountered: