diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 4a05ee0a81..aea6b05b1f 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -188,6 +188,7 @@ export default class RuntimeBackground { const totpCode = await this.autofillService.doAutoFill({ cipher: this.main.loginToAutoFill, pageDetails: this.pageDetailsToAutoFill, + fillNewPassword: true }); if (totpCode != null) { diff --git a/src/popup/vault/current-tab.component.ts b/src/popup/vault/current-tab.component.ts index 262c375d0b..374f04f0ae 100644 --- a/src/popup/vault/current-tab.component.ts +++ b/src/popup/vault/current-tab.component.ts @@ -147,6 +147,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy { cipher: cipher, pageDetails: this.pageDetails, doc: window.document, + fillNewPassword: true, }); this.analytics.eventTrack.next({ action: 'Autofilled' }); if (this.totpCode != null) { diff --git a/src/popup/vault/view.component.ts b/src/popup/vault/view.component.ts index 1e19249ba3..23f4c1c5e1 100644 --- a/src/popup/vault/view.component.ts +++ b/src/popup/vault/view.component.ts @@ -220,6 +220,7 @@ export class ViewComponent extends BaseViewComponent { cipher: this.cipher, pageDetails: this.pageDetails, doc: window.document, + fillNewPassword: true, }); if (this.totpCode != null) { this.platformUtilsService.copyToClipboard(this.totpCode, { window: window }); diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index f1530cf676..8e2c0ed145 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -126,7 +126,7 @@ export default class AutofillService implements AutofillServiceInterface { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { const formData: any[] = []; - const passwordFields = this.loadPasswordFields(pageDetails, true, true, false); + const passwordFields = this.loadPasswordFields(pageDetails, true, true, false, false); if (passwordFields.length === 0) { return formData; } @@ -174,6 +174,7 @@ export default class AutofillService implements AutofillServiceInterface { skipUsernameOnlyFill: options.skipUsernameOnlyFill || false, onlyEmptyFields: options.onlyEmptyFields || false, onlyVisibleFields: options.onlyVisibleFields || false, + fillNewPassword: options.fillNewPassword || false, cipher: options.cipher, }); @@ -241,6 +242,7 @@ export default class AutofillService implements AutofillServiceInterface { skipUsernameOnlyFill: !fromCommand, onlyEmptyFields: !fromCommand, onlyVisibleFields: !fromCommand, + fillNewPassword: fromCommand, }); } @@ -326,10 +328,12 @@ export default class AutofillService implements AutofillServiceInterface { return fillScript; } - let passwordFields = this.loadPasswordFields(pageDetails, false, false, options.onlyEmptyFields); + let passwordFields = this.loadPasswordFields(pageDetails, false, false, options.onlyEmptyFields, + options.fillNewPassword); if (!passwordFields.length && !options.onlyVisibleFields) { // not able to find any viewable password fields. maybe there are some "hidden" ones? - passwordFields = this.loadPasswordFields(pageDetails, true, true, options.onlyEmptyFields); + passwordFields = this.loadPasswordFields(pageDetails, true, true, options.onlyEmptyFields, + options.fillNewPassword); } for (const formKey in pageDetails.forms) { @@ -891,7 +895,7 @@ export default class AutofillService implements AutofillServiceInterface { } private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean, canBeReadOnly: boolean, - mustBeEmpty: boolean) { + mustBeEmpty: boolean, fillNewPassword: boolean) { const arr: AutofillField[] = []; pageDetails.fields.forEach((f) => { const isPassword = f.type === 'password'; @@ -927,7 +931,8 @@ export default class AutofillService implements AutofillServiceInterface { return false; }; if (!f.disabled && (canBeReadOnly || !f.readonly) && (isPassword || isLikePassword()) - && (canBeHidden || f.viewable) && (!mustBeEmpty || f.value == null || f.value.trim() === '')) { + && (canBeHidden || f.viewable) && (!mustBeEmpty || f.value == null || f.value.trim() === '') + && (fillNewPassword || f.autoCompleteType !== 'new-password')) { arr.push(f); } });