From 59161f61477ff450cba4aa1f8f2fc747ebba8855 Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Sun, 28 Dec 2025 22:13:58 +0100 Subject: [PATCH] nn --- extension/src/background.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/extension/src/background.ts b/extension/src/background.ts index 48daeb6..d5f2462 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -106,6 +106,8 @@ function sendMessage(message: any): void { async function syncTabGroup(): Promise { try { + // Only tabs with state 'connected' are in the group. + // Tabs in 'connecting' or 'error' state are removed from the group. const connectedTabIds = Array.from(store.getState().tabs.entries()) .filter(([_, info]) => info.state === 'connected') .map(([tabId]) => tabId) @@ -511,11 +513,18 @@ function handleConnectionClose(reason: string, code: number): void { return } - store.setState({ connectionState: 'disconnected', errorText: undefined }) - if (tabs.size > 0) { logger.debug('Tabs still connected, triggering reconnection') + store.setState((state) => { + const newTabs = new Map(state.tabs) + for (const [tabId, tab] of newTabs) { + newTabs.set(tabId, { ...tab, state: 'connecting' }) + } + return { tabs: newTabs } + }) void reconnect() + } else { + store.setState({ connectionState: 'disconnected', errorText: undefined }) } } @@ -657,6 +666,7 @@ async function disconnectTab(tabId: number): Promise { async function reconnect(): Promise { logger.debug('Starting reconnection') + store.setState({ connectionState: 'reconnecting', errorText: undefined }) const { tabs } = store.getState() const tabsToReconnect = Array.from(tabs.keys()) logger.debug('Tabs to reconnect:', tabsToReconnect) @@ -751,6 +761,8 @@ async function resetDebugger(): Promise { } } +// undefined URL is for about:blank pages (not restricted) and chrome:// URLs (restricted). +// We can't distinguish them without the `tabs` permission, so we just let attachment fail. function isRestrictedUrl(url: string | undefined): boolean { if (!url) return false const restrictedPrefixes = ['chrome://', 'chrome-extension://', 'devtools://', 'edge://'] @@ -831,11 +843,11 @@ async function updateIcons(): Promise { const iconConfig = (() => { if (connectionState === 'error') return icons.error + if (tabId !== undefined && isRestrictedUrl(tabUrl)) return icons.restricted if (connectionState === 'reconnecting') return icons.connecting if (tabInfo?.state === 'error') return icons.error if (tabInfo?.state === 'connecting') return icons.connecting if (tabInfo?.state === 'connected') return icons.connected - if (tabId !== undefined && isRestrictedUrl(tabUrl)) return icons.restricted return icons.disconnected })()