<ul dir="auto">
<li>Electron version: all</li>
<li>Operating system: OSX</li>
</ul>
<p dir="auto"><a href="https://github.com/brian-mann/electron-iframe-window-open-bug">Example repo is here.</a></p>
<p dir="auto">If you embed an <code class="notranslate">&lt;iframe&gt;</code> and then within that <code class="notranslate">&lt;iframe&gt;</code> you do this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// child returns undefined
var child = window.open(...)"><pre class="notranslate"><span class="pl-c">// child returns undefined</span>
<span class="pl-k">var</span> <span class="pl-s1">child</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-kos">)</span></pre></div>
<p dir="auto"><code class="notranslate">child</code> will be <code class="notranslate">undefined</code>, instead of the <code class="notranslate">BrowserWindowProxy</code>.</p>
<p dir="auto">Changing the code to this works by returning the proxy:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var child = window.top.open(...)"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">child</span> <span class="pl-c1">=</span> <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">top</span><span class="pl-kos">.</span><span class="pl-en">open</span><span class="pl-kos">(</span>...<span class="pl-kos">)</span></pre></div>
<p dir="auto">In my case I am embedding guest content in an <code class="notranslate">&lt;iframe&gt;</code> and cannot force the users to update their code.</p>
<ul dir="auto">
<li>Electron version: 1.3.0</li>
<li>Operating system: Windows 10</li>
</ul>
<p dir="auto"><code class="notranslate">x.js</code></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const app = require('electron').app;
const BW = require('electron').BrowserWindow;
const path = require('path');

app.once('ready', () =&gt; {

    const win = new BW({});

    win.loadURL('file://' + path.join(__dirname, 'x.html'));
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">app</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-c1">app</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-c1">BW</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-c1">BrowserWindow</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'path'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">once</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">win</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-c1">BW</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">win</span><span class="pl-kos">.</span><span class="pl-en">loadURL</span><span class="pl-kos">(</span><span class="pl-s">'file://'</span> <span class="pl-c1">+</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'x.html'</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></pre></div>
<p dir="auto"><code class="notranslate">x.html</code></p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;iframe width=&quot;100%&quot; height=&quot;200&quot; src=&quot;y.html&quot;&gt;&lt;/iframe&gt;
    XXXX
    &lt;script type=&quot;text/javascript&quot;&gt;
        function fn() {
            const w = window.open('http://electron.atom.io/');
            console.log(w);
            w.focus();
        }
    &lt;/script&gt;
    &lt;button onclick=&quot;fn()&quot;&gt;Open Window&lt;/button&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">head</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">head</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">iframe</span> <span class="pl-c1">width</span>="<span class="pl-s">100%</span>" <span class="pl-c1">height</span>="<span class="pl-s">200</span>" <span class="pl-c1">src</span>="<span class="pl-s">y.html</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">iframe</span><span class="pl-kos">&gt;</span>
    XXXX
    <span class="pl-kos">&lt;</span><span class="pl-ent">script</span> <span class="pl-c1">type</span>="<span class="pl-s">text/javascript</span>"<span class="pl-kos">&gt;</span>
        <span class="pl-k">function</span> <span class="pl-en">fn</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">const</span> <span class="pl-s1">w</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-s">'http://electron.atom.io/'</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">w</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-s1">w</span><span class="pl-kos">.</span><span class="pl-en">focus</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">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">button</span> <span class="pl-c1">onclick</span>="<span class="pl-s">fn()</span>"<span class="pl-kos">&gt;</span>Open Window<span class="pl-kos">&lt;/</span><span class="pl-ent">button</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"><code class="notranslate">y.html</code></p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="YYYY
&lt;script type=&quot;text/javascript&quot;&gt;
    function fn() {
        const w = window.open('http://electron.atom.io/');
        console.log(w);
        w.focus();
    }
&lt;/script&gt;
&lt;button onclick=&quot;fn()&quot;&gt;Open Window&lt;/button&gt;"><pre class="notranslate">YYYY
<span class="pl-kos">&lt;</span><span class="pl-ent">script</span> <span class="pl-c1">type</span>="<span class="pl-s">text/javascript</span>"<span class="pl-kos">&gt;</span>
    <span class="pl-k">function</span> <span class="pl-en">fn</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">const</span> <span class="pl-s1">w</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-s">'http://electron.atom.io/'</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">w</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">w</span><span class="pl-kos">.</span><span class="pl-en">focus</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">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">button</span> <span class="pl-c1">onclick</span>="<span class="pl-s">fn()</span>"<span class="pl-kos">&gt;</span>Open Window<span class="pl-kos">&lt;/</span><span class="pl-ent">button</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto"><code class="notranslate">w</code> is <code class="notranslate">undefined</code> when called from <code class="notranslate">y.html</code>, but not <code class="notranslate">x.html</code>. In both cases, a new BrowserWindow is created for the popup.</p>