cordova-electron icon indicating copy to clipboard operation
cordova-electron copied to clipboard

alert() and confirm() breaks focus, refocusing BrowserWindow can fix this issue

Open fabiofabbri84 opened this issue 1 year ago • 0 comments

Electron has a known bug: if you call alert() or confirm(), focus breaks, so for example you can't enter text in an input field after these functions are called. See https://github.com/electron/electron/issues/31917 and https://github.com/electron/electron/issues/41603

Losing and regaining the focus fixes this quirk, so we made a plugin that overrides alert() and confirm() in order to call BrowserWindow.getFocusedWindow().blur() and focus() on the main process after the native dialogs functions returns.

(I'm not sure if BrowserWindow.getFocusedWindow() is the best way to get the window, but it works and I think this is a good way to handle it if there are multiple windows)

So if this issue affects your Cordova Electron app, you can use our plugin: https://github.com/cimatti/cordova-electron-dialogs-fix

However I think this fix could be included in future versions of cordova-electron

fabiofabbri84 avatar Oct 01 '24 10:10 fabiofabbri84