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