diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 04a53395130..a1e8c26f0ea 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -48,6 +48,8 @@ import { Fido2CredentialView } from "@bitwarden/common/vault/models/view/fido2-c import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view"; import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view"; import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; +import { GenerateRequest } from "@bitwarden/generator-core"; +import { GeneratedCredential } from "@bitwarden/generator-history"; // FIXME (PM-22628): Popup imports are forbidden in background // eslint-disable-next-line no-restricted-imports @@ -234,7 +236,9 @@ export class OverlayBackground implements OverlayBackgroundInterface { private themeStateService: ThemeStateService, private totpService: TotpService, private accountService: AccountService, - private generatePasswordCallback: () => Promise, + private generatePasswordCallback: ( + $on: Observable, + ) => Observable, private addPasswordCallback: (password: string) => Promise, ) { this.initOverlayEventObservables(); diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 1b5d9980dce..b5e441c913e 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -3,6 +3,7 @@ import "core-js/proposals/explicit-resource-management"; import { + concatMap, filter, firstValueFrom, from, @@ -227,6 +228,8 @@ import { PasswordGenerationServiceAbstraction, UsernameGenerationServiceAbstraction, } from "@bitwarden/generator-legacy"; +import { GenerateRequest } from "@bitwarden/generator-core"; +import { GeneratedCredential } from "@bitwarden/generator-history"; import { DefaultImportMetadataService, ImportApiService, @@ -2044,6 +2047,18 @@ export default class MainBackground { await this.atRiskCipherUpdaterService.init(); } + yieldGeneratedPassword = ($on: Observable): Observable => { + return $on.pipe( + concatMap(async () => { + const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; + const password = await this.passwordGenerationService.generatePassword(options); + const credential = new GeneratedCredential(password, "password", new Date()); + + return credential; + }), + ); + }; + generatePassword = async (): Promise => { const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; return await this.passwordGenerationService.generatePassword(options);