diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index e1f0b8bfc64..156597e81e2 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1612,6 +1612,17 @@ export default class MainBackground { } } + /** Opens the `/at-risk-passwords` page within the popup */ + async openAtRisksPasswordsPage() { + const browserAction = BrowserApi.getBrowserAction(); + // Set route of the popup before attempting to open it. + // If the vault is locked, this won't have an effect as the auth guards will + // redirect the user to the login page. + await browserAction.setPopup({ popup: "popup/index.html#/at-risk-passwords" }); + + await this.openPopup(); + } + async reseedStorage() { if ( !this.platformUtilsService.isChrome() && diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 7db72f38139..5a7429b8529 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -17,6 +17,7 @@ import { devFlagEnabled } from "@bitwarden/common/platform/misc/flags"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { NotificationsService } from "@bitwarden/common/platform/notifications"; import { CipherType } from "@bitwarden/common/vault/enums"; +import { VaultMessages } from "@bitwarden/common/vault/enums/vault-messages.enum"; import { BiometricsCommands } from "@bitwarden/key-management"; import { @@ -289,6 +290,10 @@ export default class RuntimeBackground { case "openPopup": await this.openPopup(); break; + case VaultMessages.OpenAtRiskPasswords: + await this.main.openAtRisksPasswordsPage(); + this.announcePopupOpen(); + break; case "bgUpdateContextMenu": case "editedCipher": case "addedCipher": @@ -418,24 +423,6 @@ export default class RuntimeBackground { private async openPopup() { await this.main.openPopup(); - - const announcePopupOpen = async () => { - const isOpen = await this.platformUtilsService.isViewOpen(); - const tabs = await this.getBwTabs(); - - if (isOpen && tabs.length > 0) { - // Send message to all vault tabs that the extension has opened - for (const tab of tabs) { - await BrowserApi.executeScriptInTab(tab.id, { - file: "content/send-popup-open-message.js", - runAt: "document_end", - }); - } - } - }; - - // Give the popup a buffer to open - setTimeout(announcePopupOpen, 100); } async sendBwInstalledMessageToVault() { @@ -456,4 +443,25 @@ export default class RuntimeBackground { this.logService.error(`Error sending on installed message to vault: ${e}`); } } + + /** Sends a message to each tab that the popup was opened */ + private announcePopupOpen() { + const announceToAllTabs = async () => { + const isOpen = await this.platformUtilsService.isViewOpen(); + const tabs = await this.getBwTabs(); + + if (isOpen && tabs.length > 0) { + // Send message to all vault tabs that the extension has opened + for (const tab of tabs) { + await BrowserApi.executeScriptInTab(tab.id, { + file: "content/send-popup-open-message.js", + runAt: "document_end", + }); + } + } + }; + + // Give the popup a buffer to complete opening + setTimeout(announceToAllTabs, 100); + } }