<webview> / GuestView receives duplicate events for guest on re-attachment
petemill opened this issue · 2 comments
STR:
Attach a guest to a window WebContents via a . (<webview>.attachGuest(x)
)
Detach (<webview>.detachGuest()
)
Repeat
Every event that is fired (e.g. 'update-target-url', 'load-start', 'guest-ready', 'will-destroy', etc) will fire as many times as the contents has been attached.
Cause
This is due to guest-view-manager.js attaching new listeners to those events every time a guest is attached to an embedder. Those listener handlers then fire IPC message to the window embedder, which forwards to the guest view (via guest-view-internal.js).
Fix
Part of the single-webview2 branch, contained in 2fbabc6
Perhaps this is useful electron/electron@313b2fa
I created a potential fix in 2fbabc6 that introduces a new event set-window
. At first, I saw that without attaching we get process add-new-contents
event - the first event with a valid windowId, but we want to get an event every time the window changes, so we can change which embedder we're forwarding the events to. This seems to work.