<p dir="auto">Hi, I'm facing a problem that <strong>window.opener</strong> is null when there is a access to window.opener in a page within webview tag.<br>
I listen the <strong>new-window</strong> event of the webview tag,and then add a new tab.Yes, it's similar to click a a tag with <em>_blank</em> .<br>
The original behavior is that opening a new window in Chrome of <em>window.opener</em>.But now,I changed it to act as clicking a tag with <em>_blank</em> .<br>
I found a doc in <a href="url">https://github.com/electron/electron/blob/master/docs/api/window-open.md</a>.<br>
The sample code is strange,when I opened an url directly,I couldn't access window.opener in new page.<br>
like this:<br>
main.js</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const {app, BrowserWindow, m} = require('electron');
let basicWindowParams = {
        show: true
};
console.log(process.pid)
app.on('ready', () =&gt; {
    const mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
          nativeWindowOpen: true
        }
      })
      mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) =&gt; {
        
        if (frameName === 'reddit') {
          event.preventDefault()
          Object.assign(options, {
            modal: true,
            parent: mainWindow
          })
          let newWin = new BrowserWindow(options);
          event.newGuest = newWin;
          newWin.webContents.openDevTools();
        }
      });
      mainWindow.loadURL(`file://${__dirname}/index.html`)
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span>app<span class="pl-kos">,</span> BrowserWindow<span class="pl-kos">,</span> m<span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'electron'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">basicWindowParams</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
        <span class="pl-c1">show</span>: <span class="pl-c1">true</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">pid</span><span class="pl-kos">)</span>
<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'ready'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">mainWindow</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">BrowserWindow</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
        <span class="pl-c1">width</span>: <span class="pl-c1">800</span><span class="pl-kos">,</span>
        <span class="pl-c1">height</span>: <span class="pl-c1">600</span><span class="pl-kos">,</span>
        <span class="pl-c1">webPreferences</span>: <span class="pl-kos">{</span>
          <span class="pl-c1">nativeWindowOpen</span>: <span class="pl-c1">true</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-s1">mainWindow</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'new-window'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">,</span> <span class="pl-s1">url</span><span class="pl-kos">,</span> <span class="pl-s1">frameName</span><span class="pl-kos">,</span> <span class="pl-s1">disposition</span><span class="pl-kos">,</span> <span class="pl-s1">options</span><span class="pl-kos">,</span> <span class="pl-s1">additionalFeatures</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        
        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">frameName</span> <span class="pl-c1">===</span> <span class="pl-s">'reddit'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-en">preventDefault</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
          <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">assign</span><span class="pl-kos">(</span><span class="pl-s1">options</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
            <span class="pl-c1">modal</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
            <span class="pl-c1">parent</span>: <span class="pl-s1">mainWindow</span>
          <span class="pl-kos">}</span><span class="pl-kos">)</span>
          <span class="pl-k">let</span> <span class="pl-s1">newWin</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">BrowserWindow</span><span class="pl-kos">(</span><span class="pl-s1">options</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
          <span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">newGuest</span> <span class="pl-c1">=</span> <span class="pl-s1">newWin</span><span class="pl-kos">;</span>
          <span class="pl-s1">newWin</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">.</span><span class="pl-en">openDevTools</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-s1">mainWindow</span><span class="pl-kos">.</span><span class="pl-en">loadURL</span><span class="pl-kos">(</span><span class="pl-s">`file://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">__dirname</span><span class="pl-kos">}</span></span>/index.html`</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">index.html</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;html&gt;
    &lt;body&gt;
        &lt;script&gt;
            let url = 'https://reddit.com';
            let modal = window.open(url, 'reddit')
            // modal.location.href = url;
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">body</span><span class="pl-kos">&gt;</span>
        <span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
            <span class="pl-k">let</span> <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">'https://reddit.com'</span><span class="pl-kos">;</span>
            <span class="pl-k">let</span> <span class="pl-s1">modal</span> <span class="pl-c1">=</span> <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-en">open</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">,</span> <span class="pl-s">'reddit'</span><span class="pl-kos">)</span>
            <span class="pl-c">// modal.location.href = url;</span>
        <span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;/</span><span class="pl-ent">body</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">OS: Windows 7 SP1<br>
Electron: 1.7.8</p>
<ul dir="auto">
<li>Electron version: 1.7.6</li>
</ul>
<h3 dir="auto">Actual behavior</h3>

<p dir="auto">When calling <code class="notranslate">window.open</code> from an iframe no popup is open whereas the <code class="notranslate">new-window</code> events is fired on the webContents.</p>
<h3 dir="auto">Expected behavior</h3>

<p dir="auto">Would expect <code class="notranslate">window.open</code>  to open a popup even in iframe.</p>
<p dir="auto">Note that when using with <code class="notranslate">nativeWindowOpen</code> it works fine.</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">Use this PR: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="254053808" data-permission-text="Title is private" data-url="https://github.com/alexstrat/electron-quick-start/issues/1" data-hovercard-type="pull_request" data-hovercard-url="/alexstrat/electron-quick-start/pull/1/hovercard" href="https://github.com/alexstrat/electron-quick-start/pull/1">alexstrat/electron-quick-start#1</a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/687961/29882655-0045595a-8dae-11e7-97e1-609cb26a24cc.png"><img src="https://user-images.githubusercontent.com/687961/29882655-0045595a-8dae-11e7-97e1-609cb26a24cc.png" alt="screenshot 2017-08-30 18 06 40" style="max-width: 100%;"></a></p>