From 96191e5857c57d2a54fda616a9fb49d07796219d Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Fri, 3 Jan 2020 22:47:10 +0100 Subject: [PATCH] Open external URLs in OS default browser --- src/main.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 2bcb990..1017c35 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import fs from "fs"; import path from "path"; -import {app, BrowserWindow, ipcMain, Menu, Tray} from "electron"; +import {app, BrowserWindow, ipcMain, Menu, shell, Tray} from "electron"; import Config from "./Config"; @@ -60,6 +60,15 @@ function createWindow() { }); } + // Open external links in default OS browser + app.on('web-contents-created', (e, contents) => { + if (contents.getType() === 'webview') { + contents.on('new-window', (e, url) => { + e.preventDefault(); + shell.openExternal(url); + }); + } + }); // Sync services with navigation window.webContents.on('dom-ready', sendServices);