1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[PM-22454] Autofill correct login form from extension (#16680)

* [PM-22454] Autofill correct login form from extension

* Remove redundant setting of `f`

* Remove correct redundant call
This commit is contained in:
Jeffrey Holland
2025-10-06 19:26:55 +02:00
committed by GitHub
parent 8c81ccc1c5
commit f073fde443

View File

@@ -2270,6 +2270,8 @@ export default class AutofillService implements AutofillServiceInterface {
withoutForm: boolean,
): AutofillField | null {
let usernameField: AutofillField = null;
let usernameFieldInSameForm: AutofillField = null;
for (let i = 0; i < pageDetails.fields.length; i++) {
const f = pageDetails.fields[i];
if (AutofillService.forCustomFieldsOnly(f)) {
@@ -2282,22 +2284,29 @@ export default class AutofillService implements AutofillServiceInterface {
const includesUsernameFieldName =
this.findMatchingFieldIndex(f, AutoFillConstants.UsernameFieldNames) > -1;
const isInSameForm = f.form === passwordField.form;
if (
!f.disabled &&
(canBeReadOnly || !f.readonly) &&
(withoutForm || f.form === passwordField.form || includesUsernameFieldName) &&
(withoutForm || isInSameForm || includesUsernameFieldName) &&
(canBeHidden || f.viewable) &&
(f.type === "text" || f.type === "email" || f.type === "tel")
) {
usernameField = f;
// We found an exact match. No need to keep looking.
if (includesUsernameFieldName) {
break;
// Prioritize fields in the same form as the password field
if (isInSameForm) {
usernameFieldInSameForm = f;
if (includesUsernameFieldName) {
return f;
}
} else {
usernameField = f;
}
}
}
return usernameField;
// Prefer username field in same form, fall back to any username field
return usernameFieldInSameForm || usernameField;
}
/**