From 60a0d5950b55288d1c4169cb035489c8611efbb7 Mon Sep 17 00:00:00 2001 From: jackwener Date: Tue, 24 Mar 2026 02:17:36 +0800 Subject: [PATCH] refactor(extension): reuse async detach() in registerListeners Replace inline sync chrome.debugger.detach() in onUpdated listener with the shared async detach() function for consistent cleanup behavior across all detach paths. --- extension/dist/background.js | 11 ++--------- extension/src/cdp.ts | 7 ++----- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/extension/dist/background.js b/extension/dist/background.js index 08e67191..fe310f3d 100644 --- a/extension/dist/background.js +++ b/extension/dist/background.js @@ -118,15 +118,8 @@ function registerListeners() { chrome.debugger.onDetach.addListener((source) => { if (source.tabId) attached.delete(source.tabId); }); - chrome.tabs.onUpdated.addListener((tabId, info) => { - if (info.url && !isDebuggableUrl$1(info.url)) { - if (attached.has(tabId)) { - attached.delete(tabId); - try { - chrome.debugger.detach({ tabId }); - } catch {} - } - } + chrome.tabs.onUpdated.addListener(async (tabId, info) => { + if (info.url && !isDebuggableUrl$1(info.url)) await detach(tabId); }); } //#endregion diff --git a/extension/src/cdp.ts b/extension/src/cdp.ts index fa195f76..c768e13e 100644 --- a/extension/src/cdp.ts +++ b/extension/src/cdp.ts @@ -158,12 +158,9 @@ export function registerListeners(): void { if (source.tabId) attached.delete(source.tabId); }); // Invalidate attached cache when tab URL changes to non-debuggable - chrome.tabs.onUpdated.addListener((tabId, info) => { + chrome.tabs.onUpdated.addListener(async (tabId, info) => { if (info.url && !isDebuggableUrl(info.url)) { - if (attached.has(tabId)) { - attached.delete(tabId); - try { chrome.debugger.detach({ tabId }); } catch { /* ignore */ } - } + await detach(tabId); } }); }