<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="155666520" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/5602" data-hovercard-type="pull_request" data-hovercard-url="/electron/electron/pull/5602/hovercard" href="https://github.com/electron/electron/pull/5602">#5602</a> switched to static Visual C++ runtime, but there are issues with that:</p>
<ul dir="auto">
<li>The runtime is unnecessarily duplicated in <code class="notranslate">node.dll</code> and <code class="notranslate">electron.exe</code>.</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="178240711" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/7281" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/7281/hovercard" href="https://github.com/electron/electron/issues/7281">#7281</a> reports that Electron-wide native exception handling is broken because exception handlers are applied per runtime instance.</li>
<li><code class="notranslate">node.dll</code> exports some symbols of the runtime, and when a native node module uses the dynamic runtime, it can mistakenly bind to those symbols instead of the ones from <code class="notranslate">msvcp140</code> and friends. This ends up causing crashes when an object is initialized using one instance of the runtime and destroyed using the other instance.</li>
<li>Wrapper functions had to be <a href="https://github.com/electron/electron/pull/5602/commits/e609a5bee290eb32d99278e9863ea48d77792a46">introduced</a> to make even Electron itself run correctly with the statically linked runtime.</li>
</ul>
<p dir="auto">The reason why it was decided to link the runtime statically was to "remove" a dependency on the Universal CRT (UCRT). That argument is weak, because the dependency is not actually removed, but merely UCRT is also statically linked and duplicated. Therefore the real argument is to not have to redistribute the UCRT binaries for non-updated Windows 7 systems and that is not a strong enough reason to justify the above problems.</p>
<p dir="auto">So I am suggesting we move back to linking the VC runtime dynamically and redistribute it together with UCRT. I will prepare and submit a PR in the coming days.</p>
<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>