WebView: Get event parameters via WebContents rather than WebviewTag.

Works around https://github.com/electron/electron/issues/31924.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-02-02 23:25:50 -08:00
parent 3a8541f601
commit 2f7529cd71
2 changed files with 11 additions and 15 deletions

View File

@@ -130,16 +130,18 @@ export default class WebView {
}
registerListeners(): void {
this.$el.addEventListener("new-window", (event) => {
handleExternalLink.call(this, event);
const webContents = this.getWebContents();
webContents.setWindowOpenHandler((details) => {
handleExternalLink.call(this, details);
return {action: "deny"};
});
if (shouldSilentWebview) {
this.getWebContents().setAudioMuted(true);
webContents.setAudioMuted(true);
}
this.$el.addEventListener("page-title-updated", (event) => {
const {title} = event;
webContents.on("page-title-updated", (_event, title) => {
this.badgeCount = this.getBadgeCount(title);
this.props.onTitleChange();
});
@@ -152,9 +154,7 @@ export default class WebView {
this.canGoBackButton();
});
this.$el.addEventListener("page-favicon-updated", (event) => {
const {favicons} = event;
webContents.on("page-favicon-updated", (_event, favicons) => {
// This returns a string of favicons URL. If there is a PM counts in unread messages then the URL would be like
// https://chat.zulip.org/static/images/favicon/favicon-pms.png
if (
@@ -170,7 +170,6 @@ export default class WebView {
}
});
const webContents = this.getWebContents();
webContents.addListener("context-menu", (event, menuParameters) => {
contextMenu(webContents, event, menuParameters);
});
@@ -181,8 +180,7 @@ export default class WebView {
this.show();
});
this.$el.addEventListener("did-fail-load", (event) => {
const {errorDescription} = event;
webContents.on("did-fail-load", (_event, _errorCode, errorDescription) => {
const hasConnectivityError =
SystemUtil.connectivityERR.includes(errorDescription);
if (hasConnectivityError) {