<ul dir="auto">
<li>Electron version: 1.6.12 (electron-prebuilt-compile)</li>
<li>Operating system: Windows 10</li>
</ul>
<h3 dir="auto">Expected behavior</h3>

<p dir="auto">I am writing application in react. I want to create eventListener, which will send by ipcRenderer url of first webview, to another. Also some links should be blocked. I tried a lot of evens, but finally ended with <code class="notranslate">'will-navigate'</code> and <code class="notranslate">event.preventDefault()</code>.</p>
<h3 dir="auto">Actual behavior</h3>

<p dir="auto">Will-navigate doesn't work at all. It doesn't display even console logs. I checked other events. F.g <code class="notranslate">did-navigate</code> or <code class="notranslate">did-navigate-in-page</code> and from these events I received respones.</p>
<h3 dir="auto">How to reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ReactDOM.findDOMNode(this).addEventListener('did-navigate-in-page',(event) =&gt;{ console.log(&quot;did-navigate-in-page&quot;)});

ReactDOM.findDOMNode(this).addEventListener('did-navigate',(event, url) =&gt;{ console.log(&quot;did-navigate&quot;)});

ReactDOM.findDOMNode(this).addEventListener('will-navigate',(event, url) =&gt;{ console.log(&quot;will-navigate&quot;)})"><pre class="notranslate"><code class="notranslate">ReactDOM.findDOMNode(this).addEventListener('did-navigate-in-page',(event) =&gt;{ console.log("did-navigate-in-page")});

ReactDOM.findDOMNode(this).addEventListener('did-navigate',(event, url) =&gt;{ console.log("did-navigate")});

ReactDOM.findDOMNode(this).addEventListener('will-navigate',(event, url) =&gt;{ console.log("will-navigate")})
</code></pre></div>
<p dir="auto">And responses are:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="did-navigate-in-page 
did-navigate"><pre class="notranslate"><code class="notranslate">did-navigate-in-page 
did-navigate
</code></pre></div>
<p dir="auto">for some reason, the will-navigate event handler does not fire from the renderer process, i have only tested for the will-navigate event listener, am not sure if this is the behaviour of other webContents event listeners</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">the webContents will-navigate event handler should fire and prevent the window from navigating</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">the webContents will-navigate event does not fire, instead the window navigates</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">main.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { BrowserWindow, app } = require(&quot;electron&quot;);


app.on(&quot;ready&quot;, () =&gt; {
    let win = new BrowserWindow({});
    
    win.on(&quot;close&quot;, () =&gt; {
        win = null;
        app.quit();
    });

    win.webContents.openDevTools({
        mode: &quot;detached&quot;
    });    
    win.loadURL(`file://${__dirname}/index.html`);
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> BrowserWindow<span class="pl-kos">,</span> app <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"electron"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>


<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">"ready"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">win</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">BrowserWindow</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    
    <span class="pl-s1">win</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">"close"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-s1">win</span> <span class="pl-c1">=</span> <span class="pl-c1">null</span><span class="pl-kos">;</span>
        <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">quit</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-s1">win</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">.</span><span class="pl-en">openDevTools</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
        <span class="pl-c1">mode</span>: <span class="pl-s">"detached"</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>    
    <span class="pl-s1">win</span><span class="pl-kos">.</span><span class="pl-en">loadURL</span><span class="pl-kos">(</span><span class="pl-s">`file://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">__dirname</span><span class="pl-kos">}</span></span>/index.html`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">index.html</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;!doctype html&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt; Webcontents from renderer proces &lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;p&gt; Drag and Drop Something Here&lt;/p&gt;

        &lt;script&gt;
         const { remote: { getCurrentWindow } } = require(&quot;electron&quot;);
         const webContents = getCurrentWindow().webContents;
         console.log(webContents);
         webContents.on(&quot;will-navigate&quot;, (evt,filePath) =&gt; {
             evt.preventDefault();
             console.log(filePath);
         });
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
"><pre class="notranslate"><span class="pl-c1">&lt;!doctype html<span class="pl-kos">&gt;</span></span>

<span class="pl-kos">&lt;</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">head</span><span class="pl-kos">&gt;</span>
        <span class="pl-kos">&lt;</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span> Webcontents from renderer proces <span class="pl-kos">&lt;/</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;/</span><span class="pl-ent">head</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">body</span><span class="pl-kos">&gt;</span>
        <span class="pl-kos">&lt;</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span> Drag and Drop Something Here<span class="pl-kos">&lt;/</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span>

        <span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
         <span class="pl-k">const</span> <span class="pl-kos">{</span> <span class="pl-c1">remote</span>: <span class="pl-kos">{</span> getCurrentWindow <span class="pl-kos">}</span> <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"electron"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
         <span class="pl-k">const</span> <span class="pl-s1">webContents</span> <span class="pl-c1">=</span> <span class="pl-en">getCurrentWindow</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">;</span>
         <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">webContents</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
         <span class="pl-s1">webContents</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">"will-navigate"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">evt</span><span class="pl-kos">,</span><span class="pl-s1">filePath</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
             <span class="pl-s1">evt</span><span class="pl-kos">.</span><span class="pl-en">preventDefault</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
             <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">filePath</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
         <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;/</span><span class="pl-ent">body</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span></pre></div>
<ul dir="auto">
<li>Electron version: 1.7.11</li>
<li>Operating system: Gnu/Linux</li>
</ul>