fix: emit focus/blur events for webview (#14344)
* fix: emit focus/blur events for webview * test: webview can emit focus event
This commit is contained in:
parent
edd5c4b9bb
commit
459a2304b4
5 changed files with 53 additions and 21 deletions
|
@ -25,6 +25,7 @@ var v8Util = process.atomBinding('v8_util')
|
|||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter())
|
||||
|
||||
// Use electron module after everything is ready.
|
||||
const {ipcRenderer} = require('electron')
|
||||
|
||||
const {
|
||||
warnAboutNodeWithRemoteContent,
|
||||
|
@ -184,3 +185,15 @@ window.addEventListener('load', function loadHandler () {
|
|||
|
||||
window.removeEventListener('load', loadHandler)
|
||||
})
|
||||
|
||||
// Report focus/blur events of webview to browser.
|
||||
// Note that while Chromium content APIs have observer for focus/blur, they
|
||||
// unfortunately do not work for webview.
|
||||
if (process.guestInstanceId) {
|
||||
window.addEventListener('focus', () => {
|
||||
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, process.guestInstanceId)
|
||||
})
|
||||
window.addEventListener('blur', () => {
|
||||
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', false, process.guestInstanceId)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue