mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 05:43:41 +00:00
PM-6558 Vault Onboarding Extension Check on Install (#8216)
updated browser runtime background to send hasBWInstalled message on installation
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
|
|
||||||
|
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
|
||||||
|
|
||||||
import { postWindowMessage, sendExtensionRuntimeMessage } from "../spec/testing-utils";
|
import { postWindowMessage, sendExtensionRuntimeMessage } from "../spec/testing-utils";
|
||||||
|
|
||||||
describe("ContentMessageHandler", () => {
|
describe("ContentMessageHandler", () => {
|
||||||
@@ -30,9 +32,11 @@ describe("ContentMessageHandler", () => {
|
|||||||
const mockPostMessage = jest.fn();
|
const mockPostMessage = jest.fn();
|
||||||
window.postMessage = mockPostMessage;
|
window.postMessage = mockPostMessage;
|
||||||
|
|
||||||
postWindowMessage({ command: "checkIfBWExtensionInstalled" });
|
postWindowMessage({ command: VaultOnboardingMessages.checkBwInstalled });
|
||||||
|
|
||||||
expect(mockPostMessage).toHaveBeenCalled();
|
expect(mockPostMessage).toHaveBeenCalledWith({
|
||||||
|
command: VaultOnboardingMessages.HasBwInstalled,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ContentMessageWindowData,
|
ContentMessageWindowData,
|
||||||
ContentMessageWindowEventHandlers,
|
ContentMessageWindowEventHandlers,
|
||||||
@@ -33,7 +35,7 @@ const windowMessageHandlers: ContentMessageWindowEventHandlers = {
|
|||||||
* Handles the post to the web vault showing the extension has been installed
|
* Handles the post to the web vault showing the extension has been installed
|
||||||
*/
|
*/
|
||||||
function handleExtensionInstallCheck() {
|
function handleExtensionInstallCheck() {
|
||||||
window.postMessage({ command: "hasBWInstalled" });
|
window.postMessage({ command: VaultOnboardingMessages.HasBwInstalled });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -345,10 +345,34 @@ export default class RuntimeBackground {
|
|||||||
if (await this.environmentService.hasManagedEnvironment()) {
|
if (await this.environmentService.hasManagedEnvironment()) {
|
||||||
await this.environmentService.setUrlsToManagedEnvironment();
|
await this.environmentService.setUrlsToManagedEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.sendBwInstalledMessageToVault();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onInstalledReason = null;
|
this.onInstalledReason = null;
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendBwInstalledMessageToVault() {
|
||||||
|
try {
|
||||||
|
const vaultUrl = this.environmentService.getWebVaultUrl();
|
||||||
|
const urlObj = new URL(vaultUrl);
|
||||||
|
|
||||||
|
const tabs = await BrowserApi.tabsQuery({ url: `${urlObj.href}*` });
|
||||||
|
|
||||||
|
if (!tabs?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const tab of tabs) {
|
||||||
|
await BrowserApi.executeScriptInTab(tab.id, {
|
||||||
|
file: "content/send-on-installed-message.js",
|
||||||
|
runAt: "document_end",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.logService.error(`Error sending on installed message to vault: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
|
||||||
|
|
||||||
|
(function (globalContext) {
|
||||||
|
globalContext.postMessage({ command: VaultOnboardingMessages.HasBwInstalled });
|
||||||
|
})(window);
|
||||||
@@ -179,6 +179,7 @@ const mainConfig = {
|
|||||||
"overlay/list": "./src/autofill/overlay/pages/list/bootstrap-autofill-overlay-list.ts",
|
"overlay/list": "./src/autofill/overlay/pages/list/bootstrap-autofill-overlay-list.ts",
|
||||||
"encrypt-worker": "../../libs/common/src/platform/services/cryptography/encrypt.worker.ts",
|
"encrypt-worker": "../../libs/common/src/platform/services/cryptography/encrypt.worker.ts",
|
||||||
"content/lp-fileless-importer": "./src/tools/content/lp-fileless-importer.ts",
|
"content/lp-fileless-importer": "./src/tools/content/lp-fileless-importer.ts",
|
||||||
|
"content/send-on-installed-message": "./src/vault/content/send-on-installed-message.ts",
|
||||||
"content/lp-suppress-import-download": "./src/tools/content/lp-suppress-import-download.ts",
|
"content/lp-suppress-import-download": "./src/tools/content/lp-suppress-import-download.ts",
|
||||||
},
|
},
|
||||||
optimization: {
|
optimization: {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstraction
|
|||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { StateProvider } from "@bitwarden/common/platform/state";
|
import { StateProvider } from "@bitwarden/common/platform/state";
|
||||||
|
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
|
||||||
|
|
||||||
import { VaultOnboardingService as VaultOnboardingServiceAbstraction } from "./services/abstraction/vault-onboarding.service";
|
import { VaultOnboardingService as VaultOnboardingServiceAbstraction } from "./services/abstraction/vault-onboarding.service";
|
||||||
import { VaultOnboardingComponent } from "./vault-onboarding.component";
|
import { VaultOnboardingComponent } from "./vault-onboarding.component";
|
||||||
@@ -143,7 +144,9 @@ describe("VaultOnboardingComponent", () => {
|
|||||||
describe("checkBrowserExtension", () => {
|
describe("checkBrowserExtension", () => {
|
||||||
it("should call getMessages when showOnboarding is true", () => {
|
it("should call getMessages when showOnboarding is true", () => {
|
||||||
const messageEventSubject = new Subject<MessageEvent>();
|
const messageEventSubject = new Subject<MessageEvent>();
|
||||||
const messageEvent = new MessageEvent("message", { data: "hasBWInstalled" });
|
const messageEvent = new MessageEvent("message", {
|
||||||
|
data: VaultOnboardingMessages.HasBwInstalled,
|
||||||
|
});
|
||||||
const getMessagesSpy = jest.spyOn(component, "getMessages");
|
const getMessagesSpy = jest.spyOn(component, "getMessages");
|
||||||
|
|
||||||
(component as any).showOnboarding = true;
|
(component as any).showOnboarding = true;
|
||||||
@@ -151,7 +154,9 @@ describe("VaultOnboardingComponent", () => {
|
|||||||
messageEventSubject.next(messageEvent);
|
messageEventSubject.next(messageEvent);
|
||||||
|
|
||||||
void fixture.whenStable().then(() => {
|
void fixture.whenStable().then(() => {
|
||||||
expect(window.postMessage).toHaveBeenCalledWith({ command: "checkIfBWExtensionInstalled" });
|
expect(window.postMessage).toHaveBeenCalledWith({
|
||||||
|
command: VaultOnboardingMessages.checkBwInstalled,
|
||||||
|
});
|
||||||
expect(getMessagesSpy).toHaveBeenCalled();
|
expect(getMessagesSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -168,7 +173,7 @@ describe("VaultOnboardingComponent", () => {
|
|||||||
installExtension: false,
|
installExtension: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const eventData = { data: { command: "hasBWInstalled" } };
|
const eventData = { data: { command: VaultOnboardingMessages.HasBwInstalled } };
|
||||||
|
|
||||||
(component as any).showOnboarding = true;
|
(component as any).showOnboarding = true;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
|
|||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
|
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
|
import { VaultOnboardingMessages } from "@bitwarden/common/vault/enums/vault-onboarding.enum";
|
||||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||||
import { LinkModule } from "@bitwarden/components";
|
import { LinkModule } from "@bitwarden/components";
|
||||||
|
|
||||||
@@ -95,12 +96,12 @@ export class VaultOnboardingComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
void this.getMessages(event);
|
void this.getMessages(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.postMessage({ command: "checkIfBWExtensionInstalled" });
|
window.postMessage({ command: VaultOnboardingMessages.checkBwInstalled });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMessages(event: any) {
|
async getMessages(event: any) {
|
||||||
if (event.data.command === "hasBWInstalled" && this.showOnboarding) {
|
if (event.data.command === VaultOnboardingMessages.HasBwInstalled && this.showOnboarding) {
|
||||||
const currentTasks = await firstValueFrom(this.onboardingTasks$);
|
const currentTasks = await firstValueFrom(this.onboardingTasks$);
|
||||||
const updatedTasks = {
|
const updatedTasks = {
|
||||||
createAccount: currentTasks.createAccount,
|
createAccount: currentTasks.createAccount,
|
||||||
|
|||||||
6
libs/common/src/vault/enums/vault-onboarding.enum.ts
Normal file
6
libs/common/src/vault/enums/vault-onboarding.enum.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
const VaultOnboardingMessages = {
|
||||||
|
HasBwInstalled: "hasBwInstalled",
|
||||||
|
checkBwInstalled: "checkIfBWExtensionInstalled",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export { VaultOnboardingMessages };
|
||||||
Reference in New Issue
Block a user