From a42006763d639e36f713ffa93ac74b4421d27e91 Mon Sep 17 00:00:00 2001 From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:42:57 -0500 Subject: [PATCH] [PM-9455] FireFox back handling (#10867) * Refactor `POPUP_VIEW_MEMORY` to use `disk` rather than memory for the browser extension. - When FireFox opens the popup in an standalone window memory is lost, thus causing the `popup-route-history` to be lost and back navigation ceases to work * spelling * revert state definition change * add `onUpdated` event for firefox * rework observable handling * remove unneeded `from` --- .../popup-view-cache-background.service.ts | 15 +++++++++++++-- .../src/platform/state/global-state.provider.ts | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) 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 c2713f70a1..35c55633c0 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,4 +1,4 @@ -import { switchMap, merge, delay, filter, concatMap, map } from "rxjs"; +import { switchMap, merge, delay, filter, concatMap, map, first, of } from "rxjs"; import { CommandDefinition, MessageListener } from "@bitwarden/common/platform/messaging"; import { @@ -61,7 +61,18 @@ export class PopupViewCacheBackgroundService { merge( // on tab changed, excluding extension tabs fromChromeEvent(chrome.tabs.onActivated).pipe( - switchMap(([tabInfo]) => BrowserApi.getTab(tabInfo.tabId)), + 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(""))), ), diff --git a/libs/common/src/platform/state/global-state.provider.ts b/libs/common/src/platform/state/global-state.provider.ts index 5aa2b26a5b..a7179ba0f1 100644 --- a/libs/common/src/platform/state/global-state.provider.ts +++ b/libs/common/src/platform/state/global-state.provider.ts @@ -2,7 +2,7 @@ import { GlobalState } from "./global-state"; import { KeyDefinition } from "./key-definition"; /** - * A provider for geting an implementation of global state scoped to the given key. + * A provider for getting an implementation of global state scoped to the given key. */ export abstract class GlobalStateProvider { /**