From 6dca4a50950a282a27a66e18651b6f6555e2215e Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:03:32 -0500 Subject: [PATCH] [MM-50410] Allow any unhandled target=_blank links to open in the browser (#2548) --- src/main/views/webContentEvents.test.js | 6 ++++++ src/main/views/webContentEvents.ts | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/views/webContentEvents.test.js b/src/main/views/webContentEvents.test.js index dbc023ee..37c315c7 100644 --- a/src/main/views/webContentEvents.test.js +++ b/src/main/views/webContentEvents.test.js @@ -250,5 +250,11 @@ describe('main/views/webContentsEvents', () => { expect(newWindow({url: 'http://server-1.com/trusted/login'})).toStrictEqual({action: 'deny'}); expect(webContentsEventManager.popupWindow).toBeTruthy(); }); + + it('should open external URIs in browser', () => { + urlUtils.isValidURI.mockReturnValue(false); + expect(newWindow({url: 'https://google.com'})).toStrictEqual({action: 'deny'}); + expect(shell.openExternal).toBeCalledWith('https://google.com'); + }); }); }); diff --git a/src/main/views/webContentEvents.ts b/src/main/views/webContentEvents.ts index a7f0cf11..e37293a3 100644 --- a/src/main/views/webContentEvents.ts +++ b/src/main/views/webContentEvents.ts @@ -133,7 +133,6 @@ export class WebContentsEventManager { } const serverURL = WindowManager.getServerURLFromWebContentsId(webContentsId); - if (!serverURL) { shell.openExternal(details.url); return {action: 'deny'}; @@ -206,8 +205,12 @@ export class WebContentsEventManager { const contextMenu = new ContextMenu({}, this.popupWindow); contextMenu.reload(); + + return {action: 'deny'}; } + // If all else fails, just open externally + shell.openExternal(details.url); return {action: 'deny'}; }; };