diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index fc53ca4f296..72b17a14d30 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -3604,9 +3604,10 @@ describe("OverlayBackground", () => { }); it("sends a message to the list port indicating that the generated password should be updated", async () => { - sendPortMessage(listMessageConnectorSpy, { command: "refreshGeneratedPassword", portKey }); overlayBackground["credential$"].next("refresh"); + sendPortMessage(listMessageConnectorSpy, { command: "refreshGeneratedPassword", portKey }); + await flushPromises(); expect(listPortSpy.postMessage).toHaveBeenCalledWith({ diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 6870c0b096c..61612ce0486 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -1822,8 +1822,8 @@ export class OverlayBackground implements OverlayBackgroundInterface { /** * Generates a password based on the user defined password generation options. */ - private requestGeneratedPassword(source: GenerateRequest["source"]) { - this.requestGeneratedPassword$.next({ source, type: Type.password }); + private requestGeneratedPassword(request: GenerateRequest) { + this.requestGeneratedPassword$.next(request); } /** @@ -1840,7 +1840,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { */ private async updateGeneratedPassword(refreshPassword: boolean = false) { if (!this.credential$.value || refreshPassword) { - this.requestGeneratedPassword("inline-menu"); + this.requestGeneratedPassword({ source: "inline-menu", type: Type.password }); } this.postMessageToPort(this.inlineMenuListPort, { @@ -3105,7 +3105,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { } if (!this.credential$.value) { - this.requestGeneratedPassword("inline-menu.init"); + this.requestGeneratedPassword({ source: "inline-menu.init", type: Type.password }); } return true; diff --git a/apps/browser/src/background/commands.background.ts b/apps/browser/src/background/commands.background.ts index 696fd5c4f05..f115be56992 100644 --- a/apps/browser/src/background/commands.background.ts +++ b/apps/browser/src/background/commands.background.ts @@ -1,6 +1,6 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore -import { firstValueFrom } from "rxjs"; +import { firstValueFrom, Observable } from "rxjs"; import { LockService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -26,7 +26,7 @@ export default class CommandsBackground { private main: MainBackground, private platformUtilsService: PlatformUtilsService, private authService: AuthService, - private generatePasswordToClipboard: () => Promise, + private generatePasswordToClipboard: () => Observable, private accountService: AccountService, private lockService: LockService, ) { @@ -53,8 +53,8 @@ export default class CommandsBackground { private async processCommand(command: string, sender?: chrome.runtime.MessageSender) { switch (command) { - case "generate_password": - await this.generatePasswordToClipboard(); + case ExtensionCommand.GeneratePassword: + this.generatePasswordToClipboard(); break; case ExtensionCommand.AutofillLogin: await this.triggerAutofillCommand( @@ -74,10 +74,10 @@ export default class CommandsBackground { ExtensionCommand.AutofillIdentity, ); break; - case "open_popup": + case ExtensionCommand.OpenPopup: await this.openPopup(); break; - case "lock_vault": { + case ExtensionCommand.LockVault: { const activeUserId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); await this.lockService.lock(activeUserId); break; diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index ff10bfb826c..4e485e6aeb2 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -2060,12 +2060,15 @@ export default class MainBackground { ); }; - generatePasswordToClipboard = async () => { - const { credential: password } = await firstValueFrom( - this.yieldGeneratedPassword(of({ source: "clipboard", type: Type.password })), + generatePasswordToClipboard = () => { + return this.yieldGeneratedPassword(of({ source: "clipboard", type: Type.password })).pipe( + concatMap(async (generated) => { + this.platformUtilsService.copyToClipboard(generated.credential); + await this.addPasswordToHistory(generated.credential); + + return generated.credential; + }), ); - this.platformUtilsService.copyToClipboard(password); - await this.addPasswordToHistory(password); }; addPasswordToHistory = async (password: string) => {