Prevent exernal resources from being loaded by the WebView (#456)

If a user drags and drops an image, an HTML file, or other resource the
WebView understands, Electron will navigate away from the application
and load it up in the WebView, making the application unusable unless
the user restarts it.

Fixes: https://github.com/resin-io/etcher/issues/430
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-06-08 11:10:46 -04:00
parent 6c936a5192
commit 0c94de7fcf

View File

@ -81,6 +81,13 @@ electron.app.on('ready', function() {
electron.globalShortcut.unregisterAll();
});
// Prevent external resources from being loaded (like images)
// when dropping them on the WebView.
// See https://github.com/electron/electron/issues/5919
mainWindow.webContents.on('will-navigate', function(event) {
event.preventDefault();
});
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
});
});