electron open pages in external browser

This commit is contained in:
Olivier Gagnon 2021-09-21 13:32:06 -04:00
parent c564de40b3
commit c3ac16f330

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu, globalShortcut } = require("electron"); const { app, BrowserWindow, Menu, globalShortcut, shell } = require("electron");
Menu.setApplicationMenu(false); Menu.setApplicationMenu(false);
function createWindow() { function createWindow() {
@ -20,6 +20,17 @@ function createWindow() {
globalShortcut.register("f8", function () { globalShortcut.register("f8", function () {
win.loadFile("index.html", { query: { noScripts: "true" } }); 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(() => { app.whenReady().then(() => {