mirror of
https://github.com/stablyai/orca.git
synced 2026-10-21 00:03:46 +00:00
fix(browser): close guest reload destruction race
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user