mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +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:
@@ -1312,7 +1312,7 @@ export default class MainBackground {
|
|||||||
await (this.i18nService as I18nService).init();
|
await (this.i18nService as I18nService).init();
|
||||||
(this.eventUploadService as EventUploadService).init(true);
|
(this.eventUploadService as EventUploadService).init(true);
|
||||||
|
|
||||||
this.popupViewCacheBackgroundService.startObservingTabChanges();
|
this.popupViewCacheBackgroundService.startObservingMessages();
|
||||||
|
|
||||||
await this.vaultTimeoutService.init(true);
|
await this.vaultTimeoutService.init(true);
|
||||||
this.fido2Background.init();
|
this.fido2Background.init();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
import { switchMap, delay, filter, concatMap } from "rxjs";
|
||||||
// @ts-strict-ignore
|
|
||||||
import { switchMap, merge, delay, filter, concatMap, map, first, of } from "rxjs";
|
|
||||||
|
|
||||||
import { CommandDefinition, MessageListener } from "@bitwarden/common/platform/messaging";
|
import { CommandDefinition, MessageListener } from "@bitwarden/common/platform/messaging";
|
||||||
import {
|
import {
|
||||||
@@ -14,7 +12,6 @@ import {
|
|||||||
GlobalStateProvider,
|
GlobalStateProvider,
|
||||||
} from "@bitwarden/common/platform/state";
|
} from "@bitwarden/common/platform/state";
|
||||||
|
|
||||||
import { BrowserApi } from "../browser/browser-api";
|
|
||||||
import { fromChromeEvent } from "../browser/from-chrome-event";
|
import { fromChromeEvent } from "../browser/from-chrome-event";
|
||||||
|
|
||||||
const popupClosedPortName = "new_popup";
|
const popupClosedPortName = "new_popup";
|
||||||
@@ -60,7 +57,7 @@ export class PopupViewCacheBackgroundService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
startObservingTabChanges() {
|
startObservingMessages() {
|
||||||
this.messageListener
|
this.messageListener
|
||||||
.messages$(SAVE_VIEW_CACHE_COMMAND)
|
.messages$(SAVE_VIEW_CACHE_COMMAND)
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -78,27 +75,9 @@ export class PopupViewCacheBackgroundService {
|
|||||||
.pipe(concatMap(() => this.popupViewCacheState.update(() => null)))
|
.pipe(concatMap(() => this.popupViewCacheState.update(() => null)))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
|
|
||||||
merge(
|
// on popup closed, with 2 minute delay that is cancelled by re-opening the popup
|
||||||
// on tab changed, excluding extension tabs
|
fromChromeEvent(chrome.runtime.onConnect)
|
||||||
fromChromeEvent(chrome.tabs.onActivated).pipe(
|
.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(
|
|
||||||
filter(([port]) => port.name === popupClosedPortName),
|
filter(([port]) => port.name === popupClosedPortName),
|
||||||
switchMap(([port]) =>
|
switchMap(([port]) =>
|
||||||
fromChromeEvent(port.onDisconnect).pipe(
|
fromChromeEvent(port.onDisconnect).pipe(
|
||||||
@@ -108,9 +87,7 @@ export class PopupViewCacheBackgroundService {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
|
||||||
.pipe(switchMap(() => this.clearState()))
|
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user