From 0db09e33b1937c0807a96736970a153fdd129667 Mon Sep 17 00:00:00 2001 From: hawkgs Date: Thu, 18 Dec 2025 12:17:47 +0200 Subject: [PATCH] fix(devtools): false positive app not detected Since Manifest V3, the service worker (background) gets terminated after 30s of inactivity. This can break the initialization phase of DevTools or the BE-FE communication channel, if already initialized. To prevent that, we emit a heartbeat in a >30s interval. --- .../projects/shell-browser/src/app/content-script.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/devtools/projects/shell-browser/src/app/content-script.ts b/devtools/projects/shell-browser/src/app/content-script.ts index a0bec5fcd64..bd3ab8c6353 100644 --- a/devtools/projects/shell-browser/src/app/content-script.ts +++ b/devtools/projects/shell-browser/src/app/content-script.ts @@ -19,10 +19,21 @@ const port = chrome.runtime.connect({ name: `${document.title || location.href}`, }); +// Since Manifest V3, the service worker (background) +// gets terminated after 30s of inactivity. This can +// break the initialization phase of DevTools or the +// BE-FE communication channel, if already initialized. +// To prevent that, we emit a heartbeat in a >30s interval. +const HEARTBEAT_INTERVAL = 20000; // Keep below 30s +const heartbeatInterval = setInterval(() => { + port.postMessage('__NG_DEVTOOLS_BEAT'); +}, HEARTBEAT_INTERVAL); + const handleDisconnect = (): void => { localMessageBus.emit('shutdown'); localMessageBus.destroy(); chromeMessageBus.destroy(); + clearInterval(heartbeatInterval); backgroundDisconnected = true; };