From acdcf69722e13796f884bd1d1cb6d9a801d16ca5 Mon Sep 17 00:00:00 2001 From: Todd Martin <106564991+trmartin4@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:45:50 -0500 Subject: [PATCH] [PM-18549] Do not clear route or view persistence on tab change (#13523) * Do not clear route or view persistence on tab change * Renamed method --- .../browser/src/background/main.background.ts | 2 +- .../popup-view-cache-background.service.ts | 35 ++++--------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 05495472d30..bb9ec41cc7d 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1312,7 +1312,7 @@ export default class MainBackground { await (this.i18nService as I18nService).init(); (this.eventUploadService as EventUploadService).init(true); - this.popupViewCacheBackgroundService.startObservingTabChanges(); + this.popupViewCacheBackgroundService.startObservingMessages(); await this.vaultTimeoutService.init(true); this.fido2Background.init(); diff --git a/apps/browser/src/platform/services/popup-view-cache-background.service.ts b/apps/browser/src/platform/services/popup-view-cache-background.service.ts index ba5d4b73f72..98a6065189b 100644 --- a/apps/browser/src/platform/services/popup-view-cache-background.service.ts +++ b/apps/browser/src/platform/services/popup-view-cache-background.service.ts @@ -1,6 +1,4 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore -import { switchMap, merge, delay, filter, concatMap, map, first, of } from "rxjs"; +import { switchMap, delay, filter, concatMap } from "rxjs"; import { CommandDefinition, MessageListener } from "@bitwarden/common/platform/messaging"; import { @@ -14,7 +12,6 @@ import { GlobalStateProvider, } from "@bitwarden/common/platform/state"; -import { BrowserApi } from "../browser/browser-api"; import { fromChromeEvent } from "../browser/from-chrome-event"; const popupClosedPortName = "new_popup"; @@ -60,7 +57,7 @@ export class PopupViewCacheBackgroundService { ); } - startObservingTabChanges() { + startObservingMessages() { this.messageListener .messages$(SAVE_VIEW_CACHE_COMMAND) .pipe( @@ -78,27 +75,9 @@ export class PopupViewCacheBackgroundService { .pipe(concatMap(() => this.popupViewCacheState.update(() => null))) .subscribe(); - merge( - // on tab changed, excluding extension tabs - fromChromeEvent(chrome.tabs.onActivated).pipe( - switchMap((tabs) => BrowserApi.getTab(tabs[0].tabId)), - switchMap((tab) => { - // FireFox sets the `url` to "about:blank" and won't populate the `url` until the `onUpdated` event - if (tab.url !== "about:blank") { - return of(tab); - } - - return fromChromeEvent(chrome.tabs.onUpdated).pipe( - first(), - switchMap(([tabId]) => BrowserApi.getTab(tabId)), - ); - }), - map((tab) => tab.url || tab.pendingUrl), - filter((url) => !url.startsWith(chrome.runtime.getURL(""))), - ), - - // on popup closed, with 2 minute delay that is cancelled by re-opening the popup - fromChromeEvent(chrome.runtime.onConnect).pipe( + // on popup closed, with 2 minute delay that is cancelled by re-opening the popup + fromChromeEvent(chrome.runtime.onConnect) + .pipe( filter(([port]) => port.name === popupClosedPortName), switchMap(([port]) => fromChromeEvent(port.onDisconnect).pipe( @@ -108,9 +87,7 @@ export class PopupViewCacheBackgroundService { ), ), ), - ), - ) - .pipe(switchMap(() => this.clearState())) + ) .subscribe(); }