From c3ac16f3303be82c09e324a2aeecdac9a3be13fd Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Tue, 21 Sep 2021 13:32:06 -0400 Subject: [PATCH] electron open pages in external browser --- electron/main.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/electron/main.js b/electron/main.js index 71efe5820..405d4627b 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, Menu, globalShortcut } = require("electron"); +const { app, BrowserWindow, Menu, globalShortcut, shell } = require("electron"); Menu.setApplicationMenu(false); function createWindow() { @@ -20,6 +20,17 @@ function createWindow() { globalShortcut.register("f8", function () { win.loadFile("index.html", { query: { noScripts: "true" } }); }); + + win.webContents.on("new-window", function (e, url) { + // make sure local urls stay in electron perimeter + if ("file://" === url.substr(0, "file://".length)) { + return; + } + + // and open every other protocols on the browser + e.preventDefault(); + shell.openExternal(url); + }); } app.whenReady().then(() => {