diff --git a/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.test.ts b/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.test.ts index faed4102ce6..46982afd2fa 100644 --- a/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.test.ts +++ b/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.test.ts @@ -70,6 +70,7 @@ it('binds edit protection to the current main-frame document and real lifecycle for (let event = 0; event < count; event++) { guest.emit('frame-created') guest.emit('did-start-navigation', { isMainFrame: false, isSameDocument: false }) + guest.emit('did-stop-loading') } expect(changed).not.toHaveBeenCalled() expect(mainFrame.send).toHaveBeenCalledTimes(challenges) diff --git a/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.ts b/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.ts index 694a3a9cb54..0bb0d1f6a2b 100644 --- a/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.ts +++ b/src/main/browser/guest-lifecycle/manager/registration/browser-guest-discard-protection.ts @@ -128,6 +128,15 @@ export function installBrowserGuestDiscardProtection( owner.unavailable = false snapshot() } + const loadStopped = (): void => { + const needsSnapshot = owner.navigating || owner.generation === null + owner.navigating = false + if (needsSnapshot) { + snapshot() + } else { + publish() + } + } const unresponsive = (): void => { owner.unavailable = true invalidate() @@ -143,7 +152,7 @@ export function installBrowserGuestDiscardProtection( guest.on('ipc-message', report) guest.on('did-start-navigation', navigation) guest.on('dom-ready', settled) - guest.on('did-stop-loading', settled) + guest.on('did-stop-loading', loadStopped) guest.on('responsive', responsive) guest.on('unresponsive', unresponsive) guest.on('render-process-gone', unresponsive) @@ -156,7 +165,7 @@ export function installBrowserGuestDiscardProtection( guest.off('ipc-message', report) guest.off('did-start-navigation', navigation) guest.off('dom-ready', settled) - guest.off('did-stop-loading', settled) + guest.off('did-stop-loading', loadStopped) guest.off('responsive', responsive) guest.off('unresponsive', unresponsive) guest.off('render-process-gone', unresponsive)