electron: window.focus from webapp does not trigger the focus event of the BrowserWindow
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 an issue that matches the one I want to file, without success.
Issue Details
- Electron Version: 10.1.2, 9.0.4, … 4.0.4
- Operating System: Windows 10 (v 1909)
Expected Behavior
When I open a window in the webapp that’s in my BrowserWindow
, I expect that calling win.focus()
focuses the BrowserWindow
Actual Behavior
w.focus()
doesn’t do anything and doesn’t emit the focus
event
To Reproduce
This is basically this issue which was closed. The part of the issue about win.close()
not working appears to have been fixed, so I’m opening a new issue for the focus issue.
- Start the app below
- click “open window”
- click “focus window”
- observe that the window doesn’t get focused
If you run the jsfiddle in Chrome, the focus button will put focus in the window.
Notice the “focus” event of the window doesn’t fire.
(async () => {
const {app, BrowserWindow, inAppPurchase} = require('electron');
await app.whenReady();
const mainWindow = new BrowserWindow({webPreferences: {nativeWindowOpen: true}});
await mainWindow.loadURL("https://jsfiddle.net/ishats/0shxqkpw/2/");
app.on("browser-window-created", (e, win) => {
win.on("focus", () => {
console.log("doesn't get hit");
});
});
})();
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 15 (9 by maintainers)
@bpasero figured out what i was missing - will work on this today.