Filter URL type before calling openExternal

This commit is contained in:
Ben Schwartz 2018-10-24 14:04:42 -04:00
parent 23e35e1942
commit e8bf9cacae

View file

@ -88,7 +88,16 @@ function createMainWindow() {
const LOADING_WINDOW_DELAY_MS = 3000;
const handleNavigation = (event: Event, url: string) => {
shell.openExternal(url);
try {
const parsed: URL = new URL(url);
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
shell.openExternal(url);
} else {
console.warn(`Refusing to open URL with protocol "${parsed.protocol}"`);
}
} catch (e) {
console.warn('Could not parse URL: ' + url);
}
event.preventDefault();
};
win.webContents.on('will-navigate', (event: Event, url: string) => {