fix(browser): close guest reload destruction race

This commit is contained in:
Brennan Benson
2026-08-05 19:08:10 -07:00
parent 56b7b743b7
commit bd5a579850
2 changed files with 24 additions and 0 deletions
@@ -83,6 +83,24 @@ describe('reloadBrowserPageWebview', () => {
expect(webview.reload).not.toHaveBeenCalled()
})
it('reports a guest destroyed between the liveness probe and reload', () => {
const getWebContentsId = vi
.fn<() => number>()
.mockReturnValueOnce(42)
.mockImplementation(() => {
throw new Error('WebContents is destroyed')
})
const webview = createWebview({
getWebContentsId,
reload: vi.fn(() => {
throw new Error('The WebView must be attached to the DOM')
})
})
expect(reloadBrowserPageWebview(webview, { ignoreCache: false })).toBe('guest-missing')
expect(getWebContentsId).toHaveBeenCalledTimes(2)
})
// Why: pre-dom-ready reload throws too, but a live guest is already loading — recovery must not replace it.
it('reports not-ready when a live guest rejects the reload', () => {
const webview = createWebview({
@@ -57,6 +57,12 @@ export function reloadBrowserPageWebview(
webview.reload()
}
} catch {
try {
webview.getWebContentsId()
} catch {
// Why: the guest can be destroyed between the liveness probe and reload.
return 'guest-missing'
}
return 'not-ready'
}
return 'reloaded'