Skip to content

Commit aef3173

Browse files
fix(extension): add window focus change detection to lace tab activity check (#2010)
1. The Service Worker (SW) exposes an observable isLaceTabActive$, which reports changes when: • a window is closed • a tab is updated (URL changes) • a tab is activated (user switches tabs) 2. The UI subscribes to this observable. 3. After ~30 seconds of inactivity, Chrome suspends the SW due to lack of focus. 4. When the UI resubscribes to isLaceTabActive$ after the SW was suspended: • The observable restarts with its startWith value (false). • Because the SW was suspended, no tab events (from step 1) have fired, so nothing updates the observable. • As a result, the UI keeps seeing false and shows “Blockchain out of sync.” 5. Returning to the tab does not fix the issue because no event is triggered to flip isLaceTabActive$ back to true. 6. Clicking the menus works because trigger navigation changes so the tab.onUpdated event fires, which updates isLaceTabActive$ to true. ⸻ Solution • The SW should also monitor the windowFocusChanged$ event. • When the window regains focus, the event will fire, the observable emits true if the tab is still open which tells the UI it is safe to resume communication.
1 parent 9a64d22 commit aef3173

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

apps/browser-extension-wallet/src/lib/scripts/background/session/is-lace-tab-active.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ const windowRemoved$ = fromEventPattern<WindowId>(
88
(handler) => windows.onRemoved.addListener(handler),
99
(handler) => windows.onRemoved.removeListener(handler)
1010
);
11+
12+
const windowFocusChanged$ = fromEventPattern<WindowId>(
13+
(handler) => windows.onFocusChanged.addListener(handler),
14+
(handler) => windows.onFocusChanged.removeListener(handler)
15+
);
16+
1117
const tabUpdated$ = fromEventPattern(
1218
(handler) => tabs.onUpdated.addListener(handler),
1319
(handler) => tabs.onUpdated.removeListener(handler),
@@ -30,7 +36,7 @@ const getExtensionTabUrlPattern = () => {
3036
return `${url.origin}/*`;
3137
};
3238

33-
export const isLaceTabActive$ = merge(windowRemoved$, tabUpdated$, tabActivated$).pipe(
39+
export const isLaceTabActive$ = merge(windowRemoved$, tabUpdated$, tabActivated$, windowFocusChanged$).pipe(
3440
switchMap(() =>
3541
from(
3642
catchAndBrandExtensionApiError(

0 commit comments

Comments
 (0)