diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 7578f109db..6aad2decfa 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -140,7 +140,7 @@ export default class RuntimeBackground { break; case 'autofiller': case 'autofill_cmd': - const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{ + const totpCode = await this.autofillService.doAutoFillActiveTab([{ frameId: sender.frameId, tab: msg.tab, details: msg.details, diff --git a/src/services/abstractions/autofill.service.ts b/src/services/abstractions/autofill.service.ts index 0b022bc7f1..f0490b41a2 100644 --- a/src/services/abstractions/autofill.service.ts +++ b/src/services/abstractions/autofill.service.ts @@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails'; export abstract class AutofillService { getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[]; doAutoFill: (options: any) => Promise; - doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise; + doAutoFillActiveTab: (pageDetails: any, fromCommand: boolean) => Promise; } diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index b5e0345d86..f1530cf676 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -3,6 +3,8 @@ import { FieldType, } from 'jslib/enums'; +import { CipherView } from 'jslib/models/view'; + import AutofillField from '../models/autofillField'; import AutofillPageDetails from '../models/autofillPageDetails'; import AutofillScript from '../models/autofillScript'; @@ -117,6 +119,7 @@ var IsoProvinces: { [id: string]: string; } = { /* tslint:enable */ export default class AutofillService implements AutofillServiceInterface { + constructor(private cipherService: CipherService, private userService: UserService, private totpService: TotpService, private eventService: EventService) { } @@ -217,23 +220,24 @@ export default class AutofillService implements AutofillServiceInterface { } } - async doAutoFillForLastUsedLogin(pageDetails: any, fromCommand: boolean) { + async doAutoFillActiveTab(pageDetails: any, fromCommand: boolean) { const tab = await this.getActiveTab(); if (!tab || !tab.url) { return; } - const lastUsedCipher = await this.cipherService.getLastUsedForUrl(tab.url); - if (!lastUsedCipher) { - return; + let cipher: CipherView; + if (fromCommand) { + cipher = await this.cipherService.getNextCipherForUrl(tab.url); + } else { + cipher = await this.cipherService.getLastUsedForUrl(tab.url); } return await this.doAutoFill({ - cipher: lastUsedCipher, - // tslint:disable-next-line + cipher: cipher, pageDetails: pageDetails, skipTotp: !fromCommand, - skipLastUsed: true, + skipLastUsed: !fromCommand, skipUsernameOnlyFill: !fromCommand, onlyEmptyFields: !fromCommand, onlyVisibleFields: !fromCommand,