Prevent window navigation when dropping a link


Sorry if this has been asked before, but when I drag a link from a web browser or a file into an Electron window, the window navigates to that link. Supposedly overriding the will-navigate event (described here) should prevent it, but how do I use it? The following does not seem to work, or I’m doing it wrong somehow:

mainWindow.on('will-navigate', function(event) {

Thanks a lot in advance!


The event is emitted by webContents:

mainWindow.webContents.on('will-navigate', ev => {


Worked perfectly, thank you very much!