title: Cookies in an iframe inside an electron app stop working when setting custom header via webRequest.onBeforeSendHeaders
body: <p>I have an iframe in an electron app (v6.1.2) that loads an external URL. I need to load that URL with a custom header, therefore I use <code>webRequest.onBeforeSendHeaders()</code> in order to intercept the requests and insert that header. As soon as I pass <code>requestHeaders</code> to the callback parameter, cookies in the iframe stop working.</p>
  
  <p><strong>in <code>main.js</code>:</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>import { remote } from 'electron'
  // the constant MY_URL used below contains the extarnal URL
  const webRequest = remote.getCurrentWindow().webContents.session.webRequest;
  webRequest.onBeforeSendHeaders(
    {
      urls: [`${MY_URL}*`]
    },
    (details, callback) =&gt; {
      // I need to clone details.headers, as simply setting
      // details.headers['X-MY-CUSTOM-HEADER']
      // won't work
      let requestHeaders = Object.assign({}, details.headers);
      requestHeaders['X-MY-CUSTOM-HEADER'] = '1'
      // even if I set requestHeaders to details.headers, the issue persists.
      // only removing the requestHeaders property from the object below will make it work again:
      callback({ cancel: false, requestHeaders });
    },
    ['blocking', 'requestHeaders']  // doesn't make a difference,
    // and I didn't find anything cookie-related for the "extraInfoSpec" argument
  );
  </code></pre>
  
  <p><strong>PHP Script at the target URL:</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  session_start();
  var_dump(session_id());
  var_dump($_COOKIE);
  exit;
  ?&gt;
  </code></pre>
  
  <p>The (pseudo-)output of that script on every refresh of the app or iframe is this:</p>
  
  <pre><code>string(26) "(random PHP session ID different on every call here)" array(0) { }
  </code></pre>
  
  <p>If I remove the <code>requestHeaders</code> property from the callback argument in <code>main.js</code> above, the output is as desired: the PHP session ID stays the same and any cookies the target site sets persist. That's how I know that it's not an issue on the PHP side. I can also rule out that the <code>X-MY-CUSTOM-HEADER</code> itself is interfering, as even when not changing the headers at all (see code comments), the issue remains.</p>
  
  <p>Am I missing something or is this a bug in electron? Is there any way around this?</p>