title: create contents of new window from data generated in electron's main process
body: <p>I am trying to pass data from the main window of an electron application to a
  new window, which is opened as a result of a user action, but I can't seem to get the
  interprocess communication working.
  The following is a minimal example illustrating my problem.
  For the sake of conciseness, I have included all javascript-code which is part of the
  rendering process into the html-pages.</p>
  <p>body of index.html:</p>
  <pre><code>&lt;body&gt;
      &lt;h1&gt;Passing data to new window&lt;/h1&gt;
      &lt;input id=&quot;testBtn&quot; type=&quot;button&quot; value=&quot;Testclick&quot;&gt;&lt;/input&gt;
  
      &lt;script&gt;
          const { ipcRenderer } = require('electron')
          testBtn.addEventListener('click', () =&gt; {
             ipcRenderer.send('asynchronous-message', '')
             console.log(&quot;sent asynchronously&quot;)
           });
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  <p>The relevant part of the main process index.js:</p>
  <pre><code>const {app, BrowserWindow, ipcMain} = require('electron')
  
  function createWindow () {
      window = new BrowserWindow({
        webPreferences: {
           nodeIntegration: true
           },
        width: 800, height: 600
       })
      window.loadFile('index.html')
      window.openDevTools();
  }
  
  app.on('ready', createWindow);
  
  const { readFileSync } = require('fs')
  
  //sample data: read project package-file
  function readConfig () {
    const data = readFileSync('./package.json', 'utf8')
    return data
  }
  ipcMain.on('asynchronous-message', (event, arg) =&gt; {
    console.log(&quot;asynchronous-message triggered&quot;)
    console.log(arg)
    subwindow = new BrowserWindow({
        webPreferences: {
           nodeIntegration: true
           },
        width: 800, height: 600
       })
    console.log(&quot;after creating subwindow...&quot;)
    subwindow.loadFile('sub.html')
    subwindow.webContents.send('filecontents-msg', readConfig());
    subwindow.openDevTools();
  })
  </code></pre>
  <p>relevant part of sub.html:</p>
  <pre><code> &lt;body&gt;
      &lt;h1&gt;SUBWINDOW&lt;/h1&gt;
      &lt;p id=&quot;fileContents&quot;&gt;&lt;/p&gt;
    &lt;script&gt;
        console.log(&quot;executing script of sub.html&quot;)
        const { ipcRenderer } = require('electron')
        ipcRenderer.on('filecontents-msg', (event, arg) =&gt; {
            console.log(&quot;processing message filecontents-msg&quot;)
            document.getElementById(&quot;fileContents&quot;).innerHTML = arg;
        })
    &lt;/script&gt;
    &lt;/body&gt;
  </code></pre>
  <p>The script in sub.html is executed, but apparently 'filecontents-msg' is never received (i.e.
  the function body of the function passed to <code>ipcRenderer.on</code> is never executed,
  neither when I replace the line</p>
  <pre><code>subwindow.webContents.send('filecontents-msg', readConfig());
  </code></pre>
  <p>in index.js by</p>
  <pre><code>event.reply('filecontents-msg', readConfig())
  </code></pre>
  <p>Could someone please give a working example of how to pass data from the main-process to a new window,
  triggered by some user event in another window?</p>