mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
PM-4109 Vault Onboarding M2 (#7920)
Onboarding component now detects if extension is installed
This commit is contained in:
@@ -16,6 +16,7 @@ type ContentMessageWindowEventHandlers = {
|
||||
authResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
|
||||
webAuthnResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
|
||||
duoResult: ({ data, referrer }: ContentMessageWindowEventParams) => void;
|
||||
checkIfBWExtensionInstalled: () => void;
|
||||
};
|
||||
|
||||
export {
|
||||
|
||||
@@ -25,6 +25,17 @@ describe("ContentMessageHandler", () => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("handled web vault extension response", () => {
|
||||
it("sends a message 'hasBWInstalled'", () => {
|
||||
const mockPostMessage = jest.fn();
|
||||
window.postMessage = mockPostMessage;
|
||||
|
||||
postWindowMessage({ command: "checkIfBWExtensionInstalled" });
|
||||
|
||||
expect(mockPostMessage).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("handled window messages", () => {
|
||||
it("ignores messages from other sources", () => {
|
||||
postWindowMessage({ command: "authResult" }, "https://localhost/", null);
|
||||
|
||||
@@ -24,10 +24,18 @@ const windowMessageHandlers: ContentMessageWindowEventHandlers = {
|
||||
handleAuthResultMessage(data, referrer),
|
||||
webAuthnResult: ({ data, referrer }: { data: any; referrer: string }) =>
|
||||
handleWebAuthnResultMessage(data, referrer),
|
||||
checkIfBWExtensionInstalled: () => handleExtensionInstallCheck(),
|
||||
duoResult: ({ data, referrer }: { data: any; referrer: string }) =>
|
||||
handleDuoResultMessage(data, referrer),
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the post to the web vault showing the extension has been installed
|
||||
*/
|
||||
function handleExtensionInstallCheck() {
|
||||
window.postMessage({ command: "hasBWInstalled" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the auth result message from the window.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user