WebView: Use a better focus() workaround.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-11-19 15:29:08 -08:00
parent b853856317
commit 86b7da45ef

View File

@@ -227,18 +227,9 @@ export default class WebView {
}
focus(): void {
// Focus Webview and it's contents when Window regain focus.
const webContents = remote.webContents.fromId(this.$el!.getWebContentsId());
// HACK: webContents.isFocused() seems to be true even without the element
// being in focus. So, we check against `document.activeElement`.
if (webContents && this.$el !== document.activeElement) {
// HACK: Looks like blur needs to be called on the previously focused
// element to transfer focus correctly, in Electron v3.0.10
// See https://github.com/electron/electron/issues/15718
(document.activeElement as HTMLElement).blur();
this.$el!.focus();
webContents.focus();
}
this.$el!.focus();
// Work around https://github.com/electron/electron/issues/31918
this.$el!.shadowRoot?.querySelector("iframe")?.focus();
}
hide(): void {