Avoid observer handshakes on child-frame load completion

This commit is contained in:
Brennan Benson
2026-11-09 21:37:07 -08:00
parent fb972cd1be
commit fa89cc994e
2 changed files with 12 additions and 2 deletions
@@ -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)
@@ -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)