1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[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
This commit is contained in:
Todd Martin
2025-02-24 10:45:50 -05:00
committed by GitHub
parent f53b76484a
commit acdcf69722
2 changed files with 7 additions and 30 deletions

View File

@@ -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();

View File

@@ -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();
}