Electron: prevent / cancel page navigation
<p>Is there anyway to prevent or cancel page navigation in electron?</p>

<pre><code>win.webContents.on('did-start-loading', function(event, url) {
    if (event.sender.getURL().startsWith('http://xyz')) {
        event.preventDefault();
    }
})
</code></pre>

<p>The code above doesn't work since the event handler gets executed while the page keeps on navigating away.</p>

<p>Similarly, I'd also like to do the same for event 'did-get-redirect-request', to prevent certain redirect from happening.</p>

<p>Many thanks</p>