title: Electron multiple window communication
body: <p>I want to build an electron app where multiple window will load urls from a pool of urls, and send back information using ipcRender. </p>
  
  <p>My design looks something like this:</p>
  
  <p>main.js:</p>
  
  <pre><code>function foo(){
      var urls = [ urls ....]
  
      for(var i = 0; i &lt; 3; i++){
          var window = new BrowserWindow({
              webPreferences: {
                  preload: "preload.js"
              }
          })
  
          window.webContents.on("did-finish-load"), function(){
              window.webcontents.executeJavascript("helloWorld()")
              console.log(i)
          }
  
          // Omitted some checks
          window.load(urls.shift())
      }
  
      ipc.on('helloworld', function(event, data){
          console.log(data)
          if (urls.length &gt;= 1){
              event.returnValue = urls.shift();
          } else {
              event.returnValue = 'done'
          }
      })
  }
  app.on('ready', foo)
  </code></pre>
  
  <p>preload.js</p>
  
  <pre><code>helloWorld = function(){
      var result = ipc.sendSync('helloWorld', 'hey there')
      if (result != done){
          window.location = result;
      }
  }
  </code></pre>
  
  <p>The output:
      2hey there
      2hey there
      2hey there
      ....</p>
  
  <p>The current code kind of worked: it keeps on loading the url once the page finish loading and executes the helloWorld function, and I was able to get the data from the ipcMain. </p>
  
  <p>However, only 1 out of 3 window are doing this, instead of my expectation of 3 windows working sort of asynchronously. The other 2 windows are just loading the first website and doesn't do anything else.</p>
  
  <p>Why is this happening, and what should be a proper way to implement this?</p>
  
  <p>Thanks!</p>