1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

[PM-1389] Fix SSO failure when vault timeout set to "Log Out" (#5286)

* [PM-1389] don't include background page while reloading windows

* [PM-1389] update sidebar action apis

* [PM-1389] simplify return from getSidebarAction

* [PM-1380] fix device type call after browser api change
This commit is contained in:
Jake Fink 2023-05-11 13:39:37 -04:00 committed by GitHub
parent de6e0c8c3d
commit 4ece57be34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 37 deletions

View File

@ -1,3 +1,5 @@
import { DeviceType } from "@bitwarden/common/enums/device-type.enum";
import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service";
import { TabMessage } from "../types/tab-messages";
@ -217,7 +219,7 @@ export class BrowserApi {
static reloadOpenWindows() {
const views = chrome.extension.getViews() as Window[];
views
.filter((w) => w.location.href != null)
.filter((w) => w.location.href != null && !w.location.href.includes("background.html"))
.forEach((w) => {
w.location.reload();
});
@ -253,11 +255,13 @@ export class BrowserApi {
return BrowserApi.manifestVersion === 3 ? chrome.action : chrome.browserAction;
}
static getSidebarAction(win: Window & typeof globalThis) {
return BrowserPlatformUtilsService.isSafari(win)
? null
: typeof win.opr !== "undefined" && win.opr.sidebarAction
? win.opr.sidebarAction
: win.chrome.sidebarAction;
static getSidebarAction(
win: Window & typeof globalThis
): OperaSidebarAction | FirefoxSidebarAction | null {
const deviceType = BrowserPlatformUtilsService.getDevice(win);
if (deviceType !== DeviceType.FirefoxExtension && deviceType !== DeviceType.OperaExtension) {
return null;
}
return win.opr?.sidebarAction || browser.sidebarAction;
}
}

View File

@ -105,25 +105,13 @@ type OperaSidebarAction = {
*
* @link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sidebarAction
*/
type FirefoxSidebarAction = Omit<
OperaSidebarAction,
| "setBadgeText"
| "getBadgeText"
| "setBadgeBackgroundColor"
| "getBadgeBackgroundColor"
| "onFocus"
| "onBlur"
>;
type FirefoxSidebarAction = typeof browser.sidebarAction;
type Opera = {
addons: OperaAddons;
sidebarAction: OperaSidebarAction;
};
declare namespace chrome {
let sidebarAction: FirefoxSidebarAction | undefined;
}
interface Window {
opr: Opera | undefined;
opera: unknown;

View File

@ -220,10 +220,12 @@ export class UpdateBadge {
return;
}
if (this.useSyncApiCalls) {
this.sidebarAction.setIcon(options);
if (this.isOperaSidebar(this.sidebarAction)) {
await new Promise<void>((resolve) =>
(this.sidebarAction as OperaSidebarAction).setIcon(options, () => resolve())
);
} else {
await new Promise<void>((resolve) => this.sidebarAction.setIcon(options, () => resolve()));
await this.sidebarAction.setIcon(options);
}
}

View File

@ -159,13 +159,12 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return false;
}
const sidebarView = this.sidebarViewName();
const sidebarOpen =
sidebarView != null && chrome.extension.getViews({ type: sidebarView }).length > 0;
if (sidebarOpen) {
// Opera has "sidebar_panel" as a ViewType but doesn't currently work
if (this.isFirefox() && chrome.extension.getViews({ type: "sidebar" }).length > 0) {
return true;
}
// Opera sidebar has type of "tab" (will stick around for a while after closing sidebar)
const tabOpen = chrome.extension.getViews({ type: "tab" }).length > 0;
return tabOpen;
}
@ -326,16 +325,6 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this.biometricCallback();
}
sidebarViewName(): string {
if (this.win.chrome.sidebarAction && this.isFirefox()) {
return "sidebar";
} else if (this.isOpera() && typeof opr !== "undefined" && opr.sidebarAction) {
return "sidebar_panel";
}
return null;
}
supportsSecureStorage(): boolean {
return false;
}