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
BrowserWindow.isFocused() can return true when it's not (Windows only) #20464
Comments
Can you test on the latest nightly? I made some visibility and focus tracking changes a few weeks back |
Thanks for the response @MarshallOfSound. Unfortunately the issue persists in |
@MarshallOfSound does #21963 add anything helpful diagnostically? |
I still have this issu with the latest public Electron version. |
The Electron version reported on this issue is no longer supported. See our supported versions documentation. If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know. Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated. |
This is still an issue in 11.3.0. It's an edge case, but it's a real issue. Do we really need to open a new issue? @MarshallOfSound |
I am also seeing this on MacOS. Here is the code I'm using (pretty simple):
|
@andy-asana what if you put the |
@pushkin- it doesn't help from my experience. |
This was also an issue in macOS, so I sent a fix for it in #33734. :) |
@sofianguy @nornagon @MarshallOfSound It's been almost 3 years and this issue persists. People continue to comment on other issues that are closed (like #20400,) that I strongly believe are caused by this as the underlying issue. Could we get some attention on this? |
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! |
Am I missing some repro steps somewhere in this thread...? Would love to take a look but it's going to be challenging without a consistent (or at least semi-consistent) repro case. |
Thanks for the comment @nornagon! I'll try to create a repro when I can, but my backlog is huge, and it may not be possible to recreate a ready to go repro. IIRC, the situation where I could 100% consistently reproduce this was clicking a Chrome notification (on Windows 7) when the last focused window before clicking a notification was the Electron app. In that case, Electron always thought it had retained the focus when it had not. |
I had the same issue with a current Electron and a current Windows 10. |
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! |
Still relevant last I checked. |
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! |
bump |
I wonder if people can repro this on Windows 11 22H2? I strongly suspect the answer is yes, but I thought it might not repro since the way taskbar focus is handled seemed to change a bit. I'm no longer sure how to repro this now that Windows 7 is dead, but I do believe the underlying issue remains. |
this issue still remains same |
@proy1121 can you report your OS so we can have an up to date idea of where this still occurs? Perhaps it occurs even on the latest Windows builds but the way I reproed it was particular to Windows 7. |
I am getting something like this on windows 11 home 22H2 22621.1992 with Electron 25.3.2 and as simple of a boilerplate as you can get: https://gist.github.com/kcolton/6bb551200578c1629a83e578f5d9073e const { app, BrowserWindow, webContents} = require('electron')
const createWindow = () => {
console.debug('creating window')
const window = new BrowserWindow({
width: 800,
height: 600
})
window.loadFile('index.html')
setInterval(() => {
console.debug(
'IS FOCUSED?', window.isFocused(), 'IS VISIBLE:', window.isVisible(),
'IS ENABLED:', window.isEnabled(), 'FOCUSED WINDOW:', !!BrowserWindow.getFocusedWindow(), 'WEB CONTENTS GET FOCUSED WEBCONTENTS:', !!webContents.getFocusedWebContents()
)
}, 2000)
}
app.whenReady().then(() => {
console.debug('app webReady')
createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
}) Here are my repro steps. They are not 100%, but pretty frequent. (Screenshare: https://jmp.sh/Fa7IWQrV)
Once I manually focus on the app once it will start picking up it's true focus state accurately again. Some more observations:
|
Great work on this @kcolton! |
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! |
bump |
I can't easily prove this is unresolved, but I very strongly suspect it is not. |
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! |
Not stale. |
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! |
bump |
Preflight Checklist
Issue Details
6.0.11
Windows 7
&Windows 10 (1803)
Expected Behavior
Window should be focused and allow typing
Actual Behavior
Window reports being focused, but it's not.
Strangely, if I call the exact same method I used to create the demo video below via a global hotkey, the window is properly focused.
Another indication that focus truly isn't being transferred to the window is that Windows Aero darkens the glass effect on the focused window, and whatever previous window was focused does not lighten as it should when losing focus.
To Reproduce
Unknown. I have other windows in my application that work perfectly using the same, very basic:
I also tried
Screenshots
https://recordit.co/ydntE6o9dt
You can see in the video the window reports being focused and the
input
as thedocument.activeElement
. The input appears to be focused (it has the blue outline and blinking caret) - but it's not actually focused - or at least that's the only way it will allow me to type into the input.When I move focus to another window, it correctly almost always detects that it does not have focus. It failed once to report lost focus when I moved focus to Sublime Text)
When I re-focus the window with my mouse, rather than programmatically, only then does it actually become focused.
Additional Information
I tested Mac 10.13 and Linux Mint 19 and the same code works as intended there.
The text was updated successfully, but these errors were encountered: