mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-11 10:10:25 +01:00
[PM-1900] Run Process Reload on Firefox (#10149)
* Remove Firefox Exemption * Do Not Open Sidebar On Install * Run `chrome.runtime.reload` on All Browsers * Update Docs & Test Name * Should Probably Call The Sut In Test * Update Doc Comment * Update apps/browser/src/platform/browser/browser-api.ts Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> --------- Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
This commit is contained in:
parent
00bdfa1cda
commit
37523ca66b
@ -1028,12 +1028,8 @@ export default class MainBackground {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const systemUtilsServiceReloadCallback = async () => {
|
const systemUtilsServiceReloadCallback = async () => {
|
||||||
const forceWindowReload =
|
|
||||||
this.platformUtilsService.isSafari() ||
|
|
||||||
this.platformUtilsService.isFirefox() ||
|
|
||||||
this.platformUtilsService.isOpera();
|
|
||||||
await this.taskSchedulerService.clearAllScheduledTasks();
|
await this.taskSchedulerService.clearAllScheduledTasks();
|
||||||
BrowserApi.reloadExtension(forceWindowReload ? self : null);
|
BrowserApi.reloadExtension();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.systemService = new SystemService(
|
this.systemService = new SystemService(
|
||||||
|
@ -87,7 +87,7 @@ export class NativeMessagingBackground {
|
|||||||
// Reload extension to activate nativeMessaging
|
// Reload extension to activate nativeMessaging
|
||||||
chrome.permissions.onAdded.addListener((permissions) => {
|
chrome.permissions.onAdded.addListener((permissions) => {
|
||||||
if (permissions.permissions?.includes("nativeMessaging")) {
|
if (permissions.permissions?.includes("nativeMessaging")) {
|
||||||
BrowserApi.reloadExtension(null);
|
BrowserApi.reloadExtension();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,7 @@
|
|||||||
"default_title": "Bitwarden",
|
"default_title": "Bitwarden",
|
||||||
"default_panel": "popup/index.html?uilocation=sidebar",
|
"default_panel": "popup/index.html?uilocation=sidebar",
|
||||||
"default_icon": "images/icon19.png",
|
"default_icon": "images/icon19.png",
|
||||||
|
"open_at_install": false,
|
||||||
"browser_style": false
|
"browser_style": false
|
||||||
},
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
|
@ -143,7 +143,8 @@
|
|||||||
"sidebar_action": {
|
"sidebar_action": {
|
||||||
"default_title": "Bitwarden",
|
"default_title": "Bitwarden",
|
||||||
"default_panel": "popup/index.html?uilocation=sidebar",
|
"default_panel": "popup/index.html?uilocation=sidebar",
|
||||||
"default_icon": "images/icon19.png"
|
"default_icon": "images/icon19.png",
|
||||||
|
"open_at_install": false
|
||||||
},
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
"managed_schema": "managed_schema.json"
|
"managed_schema": "managed_schema.json"
|
||||||
|
@ -276,26 +276,8 @@ describe("BrowserApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("reloadExtension", () => {
|
describe("reloadExtension", () => {
|
||||||
it("reloads the window location if the passed globalContext is for the window", () => {
|
it("forwards call to extension runtime", () => {
|
||||||
const windowMock = mock<Window>({
|
BrowserApi.reloadExtension();
|
||||||
location: { reload: jest.fn() },
|
|
||||||
}) as unknown as Window & typeof globalThis;
|
|
||||||
|
|
||||||
BrowserApi.reloadExtension(windowMock);
|
|
||||||
|
|
||||||
expect(windowMock.location.reload).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reloads the extension runtime if the passed globalContext is not for the window", () => {
|
|
||||||
const globalMock = mock<typeof globalThis>({}) as any;
|
|
||||||
BrowserApi.reloadExtension(globalMock);
|
|
||||||
|
|
||||||
expect(chrome.runtime.reload).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reloads the extension runtime if a null value is passed as the globalContext", () => {
|
|
||||||
BrowserApi.reloadExtension(null);
|
|
||||||
|
|
||||||
expect(chrome.runtime.reload).toHaveBeenCalled();
|
expect(chrome.runtime.reload).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -412,18 +412,9 @@ export class BrowserApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles reloading the extension, either by calling the window location
|
* Handles reloading the extension using the underlying functionality exposed by the browser API.
|
||||||
* to reload or by calling the extension's runtime to reload.
|
|
||||||
*
|
|
||||||
* @param globalContext - The global context to use for the reload.
|
|
||||||
*/
|
*/
|
||||||
static reloadExtension(globalContext: (Window & typeof globalThis) | null) {
|
static reloadExtension() {
|
||||||
// The passed globalContext might be a ServiceWorkerGlobalScope, as a result
|
|
||||||
// we need to check if the location object exists before calling reload on it.
|
|
||||||
if (typeof globalContext?.location?.reload === "function") {
|
|
||||||
return (globalContext as any).location.reload(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chrome.runtime.reload();
|
return chrome.runtime.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
ToastService,
|
ToastService,
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
|
|
||||||
import { BrowserApi } from "../platform/browser/browser-api";
|
|
||||||
import { PopupViewCacheService } from "../platform/popup/view-cache/popup-view-cache.service";
|
import { PopupViewCacheService } from "../platform/popup/view-cache/popup-view-cache.service";
|
||||||
import { initPopupClosedListener } from "../platform/services/popup-view-cache-background.service";
|
import { initPopupClosedListener } from "../platform/services/popup-view-cache-background.service";
|
||||||
import { BrowserSendStateService } from "../tools/popup/services/browser-send-state.service";
|
import { BrowserSendStateService } from "../tools/popup/services/browser-send-state.service";
|
||||||
@ -128,16 +127,6 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
this.showNativeMessagingFingerprintDialog(msg);
|
this.showNativeMessagingFingerprintDialog(msg);
|
||||||
} else if (msg.command === "showToast") {
|
} else if (msg.command === "showToast") {
|
||||||
this.toastService._showToast(msg);
|
this.toastService._showToast(msg);
|
||||||
} else if (msg.command === "reloadProcess") {
|
|
||||||
const forceWindowReload =
|
|
||||||
this.platformUtilsService.isSafari() ||
|
|
||||||
this.platformUtilsService.isFirefox() ||
|
|
||||||
this.platformUtilsService.isOpera();
|
|
||||||
// Wait to make sure background has reloaded first.
|
|
||||||
window.setTimeout(
|
|
||||||
() => BrowserApi.reloadExtension(forceWindowReload ? window : null),
|
|
||||||
2000,
|
|
||||||
);
|
|
||||||
} else if (msg.command === "reloadPopup") {
|
} else if (msg.command === "reloadPopup") {
|
||||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
|
Loading…
Reference in New Issue
Block a user