title: Electron secondary window not receiving IPC messages
body: <p>In my typescript which is attached to the HTML being run by my app, I am creating a new window for my settings.  From what I can tell, the preloaded script is also being loaded onto the new window once it's opened, but the window isn't receiving IPC messages from the main script.</p>
  <p>Here is the preloaded script:</p>
  <pre><code>const { contextBridge, ipcRenderer } = require(&quot;electron&quot;);
  
  console.log(&quot;preloaded!&quot;);
  
  contextBridge.exposeInMainWorld(&quot;api&quot;, {
    send: (channel, data) =&gt; {
      let validChannels = [&quot;toMain&quot;, &quot;select-dirs&quot;, &quot;toSettings&quot;, &quot;fromSettings&quot;];
      if (validChannels.includes(channel)) {
        ipcRenderer.send(channel, data);
      }
    },
    receive: (channel, func) =&gt; {
      let validChannels = [&quot;fromMain&quot;, &quot;toSettings&quot;, &quot;fromSettings&quot;];
      if (validChannels.includes(channel)) {
        ipcRenderer.on(channel, (event, ...args) =&gt; func(...args));
      }
    },
  });
  </code></pre>
  <p>And here is the typescript file that I've attached to the second window's HTML.</p>
  <pre><code>(&lt;any&gt;window).api.receive(&quot;toSettings&quot;, (data: any) =&gt; {
    console.log(data);
  })
  
  var closeButton: HTMLButtonElement;
  
  var settings = &quot;&quot;;
  var settignsDir = &quot;&quot;;
  
  document.onreadystatechange = () =&gt; {
    if (document.readyState == &quot;interactive&quot;) {
      (&lt;any&gt;window).api.send(&quot;fromSettings&quot;, &quot;ready&quot;)
      closeButton = &lt;HTMLButtonElement&gt;document.getElementById(&quot;closeButton&quot;);
  
      closeButton.addEventListener(&quot;click&quot;, () =&gt; {
        (&lt;any&gt;window).api.send(&quot;toMain&quot;, &quot;refresh&quot;);
        self.close();
      });
    }
  };
  </code></pre>
  <p>I'm using the same preloaded script for my renderer and using the same receiving code, it's working just fine.  And from the second window's typescript, I can properly send IPC messages to the main process.  But I can't receive any messages on the second window.  I'm thinking I need to re-preload the file directly to the second window via the features array in <code>window.open()</code>.  Oh and here's the code that is opening the settings window.</p>
  <pre><code>window.open(
            &quot;./html/settings.html&quot;,
            &quot;_blank&quot;,
            &quot;top=200,left=600,frame=false,nodeIntegration=no&quot;
          );
  </code></pre>
  <p>According to the Electron documentation, you can also include a preload in the third-string but I can't figure out how as the documentation fails to have an example and I can't find one anywhere.</p>
  <p>In response to Kdau:</p>
  <p>Here is the requested code:</p>
  <pre><code>(&lt;any&gt;window).api.receive(&quot;fromSettings&quot;, (data: any) =&gt; {
    (&lt;any&gt;window).api.send(&quot;toSettings&quot;, &quot;WHAT!&quot;);
  })
  </code></pre>
  <p>I was mainly using it to see if the settings or child window as you called it was receiving the message.  If you could clarify what you mean by address to the child window because I thought that the preload script should be automatically parsing, &quot;ok so this channel needs to go to this receiver&quot;.</p>
  <p>I would like to point out that in the code snippet that you included returns this error:
  Argument of type '({ url }: HandlerDetails) =&gt; { frame: boolean; webPreferences: { nodeIntegration: boolean; preload: string; }; } | undefined' is not assignable to parameter of type '(details: HandlerDetails) =&gt; { action: &quot;deny&quot;; } | { action: &quot;allow&quot;; overrideBrowserWindowOptions?: BrowserWindowConstructorOptions | undefined; }'.
  Type '{ frame: boolean; webPreferences: { nodeIntegration: boolean; preload: string; }; } | undefined' is not assignable to type '{ action: &quot;deny&quot;; } | { action: &quot;allow&quot;; overrideBrowserWindowOptions?: BrowserWindowConstructorOptions | undefined; }'.
  Type 'undefined' is not assignable to type '{ action: &quot;deny&quot;; } | { action: &quot;allow&quot;; overrideBrowserWindowOptions?: BrowserWindowConstructorOptions | undefined; }'.</p>
  <p>I don't know what to do with this.</p>