fix: <webview> focus / blur events don't work with contextIsolation enabled (#29004)
This commit is contained in:
parent
16236a195b
commit
476e908269
2 changed files with 23 additions and 1 deletions
|
@ -162,7 +162,7 @@ export class WebViewImpl {
|
||||||
|
|
||||||
// Emits focus/blur events.
|
// Emits focus/blur events.
|
||||||
onFocusChange () {
|
onFocusChange () {
|
||||||
const hasFocus = document.activeElement === this.webviewNode;
|
const hasFocus = this.webviewNode.ownerDocument.activeElement === this.webviewNode;
|
||||||
if (hasFocus !== this.hasFocus) {
|
if (hasFocus !== this.hasFocus) {
|
||||||
this.hasFocus = hasFocus;
|
this.hasFocus = hasFocus;
|
||||||
this.dispatchEvent(hasFocus ? 'focus' : 'blur');
|
this.dispatchEvent(hasFocus ? 'focus' : 'blur');
|
||||||
|
|
|
@ -672,5 +672,27 @@ describe('<webview> tag', function () {
|
||||||
})`);
|
})`);
|
||||||
expect(message).to.equal('hi');
|
expect(message).to.equal('hi');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('emits focus event when contextIsolation is enabled', async () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
webviewTag: true,
|
||||||
|
contextIsolation: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await w.loadURL('about:blank');
|
||||||
|
await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
|
||||||
|
const webview = new WebView()
|
||||||
|
webview.setAttribute('src', 'about:blank')
|
||||||
|
webview.addEventListener('dom-ready', () => {
|
||||||
|
webview.focus()
|
||||||
|
})
|
||||||
|
webview.addEventListener('focus', () => {
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
document.body.appendChild(webview)
|
||||||
|
})`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue