How to open links in default browser using Electron
You can do this the way you tried using webContents
's class instance methods instead of static functions
const { app, BrowserWindow, shell } = require('electron')
app.once('ready', () => {
const handleRedirect = (e, url) => {
if (url !== e.sender.getURL()) {
e.preventDefault()
shell.openExternal(url)
}
}
const win = new BrowserWindow()
// Instead bare webContents:
win.webContents.on('will-navigate', handleRedirect)
win.loadURL('http://google.com')
})