Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Removing <webview> from DOM destroys most-recently-attached WebContents #510

Open
petemill opened this issue Feb 26, 2018 · 2 comments
Open
Assignees
Labels
PR/work-in-progress ⚒ single-webview Supporting the single-webview project

Comments

@petemill
Copy link
Member

petemill commented Feb 26, 2018

...even if the WebContents has been detached from the webview via <webview>.detachGuest()

This issue can be demonstrated through browser-laptop using the --debug-tab-events flag, and affects the single-webview2 branch, where once a webview is detached from a tab, the tab has no more attachments remaining. Perhaps there is some logic somewhere that looks to see if the WebContents is embedded anywhere currently, after its last embbeder gets removed, and destroys it if not.

STR:

  • Create 1 window with 2 tabs
  • Create the following function in the renderer window console:
function createAttachedWebview (guestId) {
    var w = document.createElement('webview')
    w.style.position = 'fixed'
    w.style.bottom = '0'
    w.style.left = '0'
    w.style.right = '0'
    w.style.height = '40vh'
    document.body.appendChild(w)
    w.attachGuest(guestId)
    return w
}
  • find the guestInstanceId of one of the tabs through adding debug output (probably 1 or 2 - I added a data-guest-instance-id attribute to the Tab component), or just guess.

  • Create a webview attached to one of those tabs: var w = createAttachedWebview(1).

  • Observe that a new webview is created and displays the tab's contents.

  • Detach from the WebContents: w.detachGuest().

  • Observe that the webview does not display any contents anymore.

  • Remove the webview from the DOM: w.remove().

  • Problem: The WebContents is destroyed (as evidenced by the tab also being removed from the tab bar).

  • Expected: The WebContents is unaffected and can continue being attached to a different <webview>

Note that if a <webview> is attached to multiple Tab/WebContents, when it removed from the DOM, it will only cause the most-recently attached WebContents to be destroyed.

Why do we need this?

In the single-webview2 branch, I have started to use a new <webview> for each active tab and ta preview, for the following reasons:

  • Fade between preview webcontents and active webcontents using opacity.
  • Avoid white flash between sequential attachGuest(x) calls (i.e. switching active tabs).
  • Avoid bugs in webview when attaching to different guests (no painting of new contents until window resize / forced paint).
  • Avoid bugs in webview when destroying a previously-attached guest (webview will never paint anything again).
@petemill petemill self-assigned this Mar 1, 2018
@petemill petemill added the single-webview Supporting the single-webview project label Mar 1, 2018
petemill added a commit to brave/browser-laptop that referenced this issue Mar 1, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Mar 2, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
@petemill
Copy link
Member Author

petemill commented Mar 2, 2018

Proposed fix at 32ebe0b on single-webview2 branch, cc @bridiver

petemill added a commit to brave/browser-laptop that referenced this issue Mar 20, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
@nessup
Copy link

nessup commented Mar 28, 2018

Will this get merged? I have an app that uses muon and am currently stuck. The workaround referenced after the fix is brilliant and I'm gonna use it for now.

petemill added a commit to brave/browser-laptop that referenced this issue Mar 31, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 1, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 2, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 4, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 4, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 10, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 10, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 10, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 10, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 10, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 11, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 11, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 11, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 30, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue Apr 30, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue May 1, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
petemill added a commit to brave/browser-laptop that referenced this issue May 2, 2018
If a <webview> is removed from DOM, it will force the last-previously-attached WebContents to be destroyed, even if detachGuest is called, so we create a new WebContents and attach it to the tab's previous <webview> so that now when the element is removed, the temporary WebContents is destroyed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR/work-in-progress ⚒ single-webview Supporting the single-webview project
Projects
None yet
Development

No branches or pull requests

2 participants