electron: [Bug]: Hiding a window doesn't restore focus to the main window
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Electron Version
12.0.1
What operating system are you using?
Windows
Operating System Version
Windows 10 1909
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
I expect that when I hide a secondary window (perhaps the last visible secondary window), focus returns to the main window.
Actual Behavior
Focus does not return to the main window
Testcase Gist URL
No response
- start main.js
- in the devtools, open a window (
window.open("https://google.com", "a")) - when the window hides in 2 seconds, observe that focus doesn’t return to the main window
Affects both windows that are owned by the main window, and regular, standalone windows.
This is a continuation of this closed issue.
main.js:
const { app, BrowserWindow } = require('electron')
async function createWindow() {
const mainWindow = new BrowserWindow({ webPreferences: { nativeWindowOpen: true } });
await mainWindow.loadURL("https://google.com");
mainWindow.webContents.on("new-window", async (e, url, frameNAme, disp, opts) => {
opts.parent = mainWindow;
});
app.on("browser-window-created", (e, win) => {
setTimeout(() => {
win.hide();
}, 2000);
});
mainWindow.webContents.openDevTools();
}
app.whenReady().then(createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 27 (4 by maintainers)
bump
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, “bump”), and we’ll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!