From 6a2b55f23b7655bf536ac569d08b6b59a6f39f54 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 1 Jun 2026 11:55:17 -0700 Subject: [PATCH] [eric] browser: wait briefly for webview re-register before card-not-found to absorb the remount race --- frontend/src/shared/browserCommandHandler.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/shared/browserCommandHandler.ts b/frontend/src/shared/browserCommandHandler.ts index 45e45a90..631daffd 100644 --- a/frontend/src/shared/browserCommandHandler.ts +++ b/frontend/src/shared/browserCommandHandler.ts @@ -574,11 +574,25 @@ async function handleEvaluate(wv: BrowserWebview, params: Record): } } +// The registry is renderer-local and a card briefly unregisters on remount / +// tab-switch; a command landing in that gap shouldn't hard-fail. Wait a bounded +// window for (re)registration before giving up, so the error stays a real +// "card is gone" signal rather than a transient race. +async function awaitWebview(browserId: string, tabId?: string): Promise { + const deadline = Date.now() + 2000; + let wv = getWebview(browserId, tabId); + while (!wv && Date.now() < deadline) { + await new Promise((r) => setTimeout(r, 100)); + wv = getWebview(browserId, tabId); + } + return wv; +} + async function handleBrowserCommand(data: Record) { const { request_id, action, browser_id, tab_id, params = {} } = data; if (!request_id) return; - const wv = getWebview(browser_id, tab_id || undefined); + const wv = await awaitWebview(browser_id, tab_id || undefined); if (!wv) { dashboardWs.send('browser:result', { request_id,