You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macOS: window.focus() does not focus window anymore #19920
@bpasero This will be caused by the UX change we made in #16400
Can you describe your use case for seizing focus when your app isn't the focused app, it's generally bad UX for another app to randomly take focus away from another.
Reacted by Ionuț G. Stan
Reacted by Luke Bradshaw, Ali Saeed, Kevin Liang, Johnny Opao, Divyahans Gupta, Joseph Weidinger, Elena Dikareva, Alexey Lindberg, Jordan Wallet, Jupp Mueller and 9 more
@MarshallOfSound starting VSCode from the terminal when VSCode is already running should bring the window of VSCode to the foreground as it used to be.
@MarshallOfSound , any response to the other posts here for legitimate uses of this feature that was taken away?
The whole point of the app I'm writing is to toggle the app from anywhere using a hotkey, which is not possible with the newest versions of Electron. Can't developers and UX people decide what is good/bad UX for their use case instead of this library?
Reacted by Ron Masas, Dennki, Carlos Galarza, Luke Bradshaw, Tom Watson, Dom H, Mahesh Bandara Wijerathna, odusseys, potapoe, Scott Porter and 1 more
Reacted by NickPepper, Carlos Galarza, Dom H and potapoe
Reacted by Elena Dikareva, Carlos Galarza and Dom H
Same issue in 7.3.0.
I'm making a multi-window app that the main-window opens sub-windows and should be able to call them up. The feature works well even in browser.
Cannot know why electron trim this off.
Because it causes all Electron apps to steal focus from the running app, even when they don't need to. This causes apps to steal focus no matter what you're doing in another app, whether the user requested the app be made frontmost or not.
There are legitimate reasons to do this, such as if your app only runs in the background, and doesn't appear in the Dock. That being said, this stealing of focus should always be done as a result of a user's direct action, and always immediate.
Making this an explicit option, as was done in #22612 is an excellent move.
Reacted by Dennki
Reacted by Mahesh Bandara Wijerathna, SudoUser and Scott Porter
I know this is old, but this issue came up for me as well. On MacOS, the only way that I was able to get this to work was be below (only tested on MacOS):
let mainWindow
...
// mac: option + cmd + i
// win: alt + ctrl + i
globalShortcut.register('Alt+CommandOrControl+I', () => {
forceFocusWindow(mainWindow);
console.log('it works!')
})
...
function forceFocusWindow(window) {
// mac specific
if (process.platform === 'darwin')
app.focus({ steal: true });
// windows/linux specific
else {
// return if there is currently no application window
if (!window) return;
// Restore the window if it's minimized.
if (window.isMinimized()) window.restore();
// Show the window in case it's hidden.
window.show();
}
Activity
MarshallOfSound commentedon Aug 24, 2019
@bpasero This will be caused by the UX change we made in #16400
Can you describe your use case for seizing focus when your app isn't the focused app, it's generally bad UX for another app to randomly take focus away from another.
bpasero commentedon Aug 24, 2019
@MarshallOfSound starting VSCode from the terminal when VSCode is already running should bring the window of VSCode to the foreground as it used to be.
MarshallOfSound commentedon Aug 24, 2019
@bpasero How are you doing that communication? Are you using the single instance lock?
bpasero commentedon Aug 24, 2019
@MarshallOfSound we have never been using the Electron API for that purpose but have our own socket that we communicate through, just using node APIs.
luke255 commentedon Sep 18, 2019
As per the
Event: 'second-instance'section of the Electron documentation:This is no longer possible, along with any other legitimate use for this functionality.
Will this change be reverted, or will
window.focus()be deprecated on Windows and Linux also?jsphweid commentedon Jan 21, 2020
@MarshallOfSound , any response to the other posts here for legitimate uses of this feature that was taken away?
The whole point of the app I'm writing is to toggle the app from anywhere using a hotkey, which is not possible with the newest versions of Electron. Can't developers and UX people decide what is good/bad UX for their use case instead of this library?
mksmtn commentedon Apr 5, 2020
Seems to be resolved here #22612
Noctsyndrome commentedon May 29, 2020
Same issue in 7.3.0.
I'm making a multi-window app that the main-window opens sub-windows and should be able to call them up. The feature works well even in browser.
Cannot know why electron trim this off.
electron-triage commentedon Mar 9, 2021
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.
tonyarnold commentedon Sep 10, 2021
Because it causes all Electron apps to steal focus from the running app, even when they don't need to. This causes apps to steal focus no matter what you're doing in another app, whether the user requested the app be made frontmost or not.
There are legitimate reasons to do this, such as if your app only runs in the background, and doesn't appear in the Dock. That being said, this stealing of focus should always be done as a result of a user's direct action, and always immediate.
Making this an explicit option, as was done in #22612 is an excellent move.
j-lord commentedon Apr 7, 2024
I know this is old, but this issue came up for me as well. On MacOS, the only way that I was able to get this to work was be below (only tested on MacOS):
feat: agent ability to focus a page in the editor (PRD-7183) (#2269)