<p dir="auto">my goal is to create a browser window, have it load multiple pages (e.g. clicking links, loading new page etc in same window) but having the ipc available from the window on each page it loads so I can send data back to the server process</p>
<p dir="auto">I have a <code class="notranslate">preload</code> script that does <code class="notranslate">global.ELECTRON_IPC = require('ipc')</code> and I have <code class="notranslate">node-integration: false</code> to not expose anything else</p>
<p dir="auto">When I create a browser window and call <code class="notranslate">loadUrl</code>, then wait for <code class="notranslate">dom-ready</code>, the <code class="notranslate">ELECTRON_IPC</code> variable is there</p>
<p dir="auto">However, when I click on a link (causing the window to navigate to a new url), and wait for <code class="notranslate">dom-ready</code> again, the <code class="notranslate">ELECTRON_IPC</code> variable is not there this time.</p>
<p dir="auto">I'm guessing this behavior is because preload only gets called when the browser window is created. Would it make sense to call it before each load? e.g. after <code class="notranslate">will-navigate</code>?</p>
<p dir="auto">Another way to ask the question would be: how else could I only expose IPC communications from the renderer to the server (but nothing else) in a way that is available across <code class="notranslate">loadUrl</code> calls?</p>
<p dir="auto">Browser-Window node-integration breaks after POST. require / global are undefined in browser-window after a POST request. I've seen this behavior since I first used Electron - 0.26.0. Still happens in 0.28.1. Here is simple way to reproduce:</p>
<p dir="auto">package.json</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
&quot;name&quot;: &quot;PostExample&quot;,
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;main&quot;: &quot;main.js&quot;,
&quot;description&quot;: &quot;Post Loses Global&quot;
}   "><pre class="notranslate"><code class="notranslate">{
"name": "PostExample",
"version": "0.1.0",
"main": "main.js",
"description": "Post Loses Global"
}   
</code></pre></div>
<p dir="auto">main.js</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var app = require('app')
var BrowserWindow = require('browser-window')

var mainWindow = null;

app.on('window-all-closed', function() {
    app.quit()
});

app.on('ready', function() {

    mainWindow = new BrowserWindow({ 
        &quot;node-integration&quot;: true,
    });

    mainWindow.loadUrl('file://' + __dirname + '/index.html')

    mainWindow.openDevTools()

});"><pre class="notranslate"><code class="notranslate">var app = require('app')
var BrowserWindow = require('browser-window')

var mainWindow = null;

app.on('window-all-closed', function() {
    app.quit()
});

app.on('ready', function() {

    mainWindow = new BrowserWindow({ 
        "node-integration": true,
    });

    mainWindow.loadUrl('file://' + __dirname + '/index.html')

    mainWindow.openDevTools()

});
</code></pre></div>
<p dir="auto">index.html</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;html&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
    console.log(typeof global)
    try{
        var fs = require(&quot;fs&quot;);
    } catch(e){
        console.warn(&quot;ERROR&quot;, e)
    }
 &lt;/script&gt;
&lt;body&gt;
 &lt;h1&gt;Posts to self&lt;/h1&gt;
 &lt;form action=&quot;&quot; method=&quot;post&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;somevar&quot; value=&quot;val&quot; /&gt;
    &lt;button type=&quot;submit&quot;&gt;Submit to see Error&lt;/button&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;"><pre class="notranslate"><code class="notranslate">&lt;html&gt;
 &lt;script type="text/javascript"&gt;
    console.log(typeof global)
    try{
        var fs = require("fs");
    } catch(e){
        console.warn("ERROR", e)
    }
 &lt;/script&gt;
&lt;body&gt;
 &lt;h1&gt;Posts to self&lt;/h1&gt;
 &lt;form action="" method="post"&gt;
    &lt;input type="text" name="somevar" value="val" /&gt;
    &lt;button type="submit"&gt;Submit to see Error&lt;/button&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre></div>