const {EventEmitter} = require('events')
const {app, ipcMain, session, Menu, NavigationController} = require('electron')
+const {getAllWebContents} = process.atomBinding('web_contents')
// session is not used here, the purpose is to make sure session is initalized
// before the webContents module.
fromId (id) {
return binding.fromId(id)
},
- getAllWebContents () {
- return binding.getAllWebContents()
+
+ getFocusedWebContents () {
+ let focused = null
+ for (let contents of getAllWebContents()) {
+ if (!contents.isFocused()) continue
+
+ // Return webview web contents which may be embedded inside another
+ // web contents that is also reporting as focused
+ if (contents.getType() === 'webview') return contents
+
+ if (focused == null) focused = contents
+ }
+ return focused
}
}