<ul dir="auto">
<li>Electron Version: 2.0.0</li>
<li>Operating System (Platform and Version): macOS High Sierra 10.13.3</li>
<li>Last known working Electron version: N/A</li>
</ul>
<p dir="auto"><strong>Expected Behavior</strong><br>
When creating a new webview and assigning a <code class="notranslate">guestinstance</code> attribute copied from another webview, the new webview should take on the <code class="notranslate">guestinstance</code> attribute value.</p>
<p dir="auto"><strong>Actual behavior</strong><br>
When creating a new webview and assigning a <code class="notranslate">guestinstance</code> attribute copied from another webview, the new webview's <code class="notranslate">guestinstance</code> attribute value is <code class="notranslate">undefined</code>.</p>
<p dir="auto"><strong>To Reproduce</strong><br>
I created a sample repo here, the <a href="https://github.com/nos/electron-move-webview/commit/a9091bc9ae48ed37c9ae81ae9edcc3a5930668f3">last commit</a> containing the example code that demonstrates the issue.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ git clone https://github.com/nos/electron-move-webview
$ cd electron-move-webview
$ yarn install &amp;&amp; yarn start"><pre class="notranslate">$ git clone https://github.com/nos/electron-move-webview
$ <span class="pl-c1">cd</span> electron-move-webview
$ yarn install <span class="pl-k">&amp;&amp;</span> yarn start</pre></div>
<p dir="auto">This is the code in a nutshell:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="moveWebview = (existingWebview, container) =&gt; {
  const { attributes } = existingWebview;
  const webview = document.createElement('webview');

  console.log('original guestinstance:', existingWebview.guestinstance); // &quot;2&quot;

  for (let i = 0; i &lt; attributes.length; i += 1) {
    webview.setAttribute(attributes[i].nodeName, attributes[i].nodeValue);
  }

  console.log('copied guestinstance:', webview.guestinstance); // undefined

  document.body.appendChild(webview);
  existingWebview.parentNode.removeChild(existingWebview);

  return webview;
}"><pre class="notranslate"><span class="pl-en">moveWebview</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">existingWebview</span><span class="pl-kos">,</span> <span class="pl-s1">container</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-kos">{</span> attributes <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">existingWebview</span><span class="pl-kos">;</span>
  <span class="pl-k">const</span> <span class="pl-s1">webview</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">createElement</span><span class="pl-kos">(</span><span class="pl-s">'webview'</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-s">'original guestinstance:'</span><span class="pl-kos">,</span> <span class="pl-s1">existingWebview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// "2"</span>

  <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">attributes</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s1">webview</span><span class="pl-kos">.</span><span class="pl-en">setAttribute</span><span class="pl-kos">(</span><span class="pl-s1">attributes</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">nodeName</span><span class="pl-kos">,</span> <span class="pl-s1">attributes</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">nodeValue</span><span class="pl-kos">)</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-s">'copied guestinstance:'</span><span class="pl-kos">,</span> <span class="pl-s1">webview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// undefined</span>

  <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-kos">.</span><span class="pl-en">appendChild</span><span class="pl-kos">(</span><span class="pl-s1">webview</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-s1">existingWebview</span><span class="pl-kos">.</span><span class="pl-c1">parentNode</span><span class="pl-kos">.</span><span class="pl-en">removeChild</span><span class="pl-kos">(</span><span class="pl-s1">existingWebview</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">webview</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The behavior is the same if I replace the for-loop above with this one-liner:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="webview.guestinstance = existingWebview.guestinstance;"><pre class="notranslate"><span class="pl-s1">webview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span> <span class="pl-c1">=</span> <span class="pl-s1">existingWebview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Screenshots</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/169093/40881666-2dfe7832-6692-11e8-8470-cfb56200fbe3.gif"><img src="https://user-images.githubusercontent.com/169093/40881666-2dfe7832-6692-11e8-8470-cfb56200fbe3.gif" alt="electron-move-webview" data-animated-image="" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Additional Information</strong></p>
<ul dir="auto">
<li>This doesn't seem to be consistent.  In the scenario I'm seeing it, it's happening when moving from one DOM element B to A, but not from A to B.  Element B appears later in the DOM, in case it's relevant.</li>
<li>In the scenario where this does assign the <code class="notranslate">guestinstance</code> value properly, the second webview never actually loads the content.  It behaves like an empty <code class="notranslate">div</code>.</li>
<li>A hunch from the above info -- it seems like the <code class="notranslate">webContent</code> might be unloading on the first move, and so the guestinstance isn't able to be assigned on the second move.  I'm not sure why the content isn't loading on the first move though.</li>
</ul>
<ul dir="auto">
<li>Electron version: 1.8.3</li>
<li>Operating system: MacOS 10.13.3</li>
</ul>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">For code that attempts to move a webview's contents to a new webview before the first webview is about to be unmounted from the dom:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const originalWebview = document.getElementById('webview1')

setTimeout(() =&gt; {
    const newWebview = document.createElement('webview');
    newWebview.guestinstance = originalWebview.guestinstance
    document.body.appendChild(newWebview);
    document.body.removeChild(originalWebview);
}, 1000);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">originalWebview</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">getElementById</span><span class="pl-kos">(</span><span class="pl-s">'webview1'</span><span class="pl-kos">)</span>

<span class="pl-en">setTimeout</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">newWebview</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">createElement</span><span class="pl-kos">(</span><span class="pl-s">'webview'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">newWebview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span> <span class="pl-c1">=</span> <span class="pl-s1">originalWebview</span><span class="pl-kos">.</span><span class="pl-c1">guestinstance</span>
    <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-kos">.</span><span class="pl-en">appendChild</span><span class="pl-kos">(</span><span class="pl-s1">newWebview</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-kos">.</span><span class="pl-en">removeChild</span><span class="pl-kos">(</span><span class="pl-s1">originalWebview</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-c1">1000</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">After the timeout, the second webview should have the content of the first webview</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">The second webview does not receive the  content</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto"><a href="https://github.com/mjbvz/electron-webview-guestinstance-on-unmount">Repo</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="git clone https://github.com/mjbvz/electron-webview-guestinstance-on-unmount
cd electron-webview-guestinstance-on-unmount
npm install
npm start"><pre class="notranslate"><code class="notranslate">git clone https://github.com/mjbvz/electron-webview-guestinstance-on-unmount
cd electron-webview-guestinstance-on-unmount
npm install
npm start
</code></pre></div>