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
Add 'focus' & 'blur' events to BrowserView/WebContents #22201
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.
Problem Description
When working with BrowserViews, there's no way to listen to focus changes on either BrowserView itself or its WebContents.
Proposed Solution
On BrowserWindow, there are focus and blur events. The same events need to be emitted on BrowserView/WebContents.
i.e. :
browserView.on('focus', () => {
// view is focused, do stuff
});
or
browserView.webContents.on('focus', () => {
// contents are focused, do stuff
});
Alternatives Considered
I can't think of a good way of working around this lack of functionality
Reacted by TheGoddessInari, Eryk Rakowski, Luis Espinola, David Hamberlin, Michael M. Coates, Thomas O'Connor, Ricardo De Peña, Aziz Yokubjonov, mmmkkaaayy, Sam Maddock and 6 more
Hello I too would like the same event emitted. To keep track of the active. Though for my use case (applying a global keyboard shortcut to tab) I've gotten around with this.
I say quasi-focus event because it will be emitted even when the webContents are already focused (but sometimes it's good enough). You could also try use it and implement tracking of which webContents are currently focused and put it together to emulate a real focus event. And if you use webContents.focus() - it would have to be taken into account as well.
Still, a built-in implementation would surely be appreciated :)
Activity
Lee182 commentedon May 7, 2020
Hello I too would like the same event emitted. To keep track of the active. Though for my use case (applying a global keyboard shortcut to tab) I've gotten around with this.
mckravchyk commentedon Nov 13, 2021
It won't help with every scenario, but you can have a quasi-focus event by tapping to pointerdown.
Minimal example:
(add to preload, and ensure preload is also in iframes (option
webPreferences.nodeIntegrationInSubFrames: true):I say quasi-focus event because it will be emitted even when the webContents are already focused (but sometimes it's good enough). You could also try use it and implement tracking of which webContents are currently focused and put it together to emulate a real focus event. And if you use
webContents.focus()- it would have to be taken into account as well.Still, a built-in implementation would surely be appreciated :)