Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add form detector improvements and tests (#794)

Leendert de Borst8526172ec7b6
diff --git a/browser-extension/src/utils/formDetector/FormDetector.ts b/browser-extension/src/utils/formDetector/FormDetector.ts
index 345ddb9b2..be93e256f 100644
--- a/browser-extension/src/utils/formDetector/FormDetector.ts
+++ b/browser-extension/src/utils/formDetector/FormDetector.ts
@@ -295,6 +295,17 @@ export class FormDetector {
}
}
+ // Check for sibling elements with class containing "label"
+ const parent = input.parentElement;
+ if (parent) {
+ const siblings = Array.from(parent.children);
+ for (const sibling of siblings) {
+ if (sibling !== input && Array.from(sibling.classList).some(c => c.toLowerCase().includes('label'))) {
+ attributes.push(sibling.textContent?.toLowerCase() ?? '');
+ }
+ }
+ }
+
// Check for parent label and table cell structure
let currentElement = input;
for (let i = 0; i < 5; i++) {
diff --git a/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts b/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
index b707cfc0b..f24f90d40 100644
--- a/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
+++ b/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
@@ -76,4 +76,11 @@ describe('FormDetector English tests', () => {
testField(FormField.Email, 'resolving_input', htmlFile);
});
+
+ describe('English login form 2 detection', () => {
+ const htmlFile = 'en-login-form2.html';
+
+ testField(FormField.Email, 'account_name_text_field', htmlFile);
+ });
+
});
diff --git a/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form2.html b/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form2.html
new file mode 100644
index 000000000..d239a7c4d
--- /dev/null
+++ b/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form2.html
@@ -0,0 +1,12 @@
+<!--
+Apple ID login form where the label is a sibling element of the input field without proper label[for] attribute.
+The element here should be detected as an email field.
+-->
+<div>
+ <div class=" form-cell-wrapper form-textbox ">
+ <input type="text" id="account_name_text_field" can-field="accountName" aria-labelledby="apple_id_field_label" autocorrect="off" autocapitalize="off" aria-required="true" required="required" spellcheck="false" ($focus)="appleIdFocusHandler($element)" ($blur)="appleIdBlurHandler()" class="force-ltr form-textbox-input form-textbox-entered " autocomplete="false" aria-invalid="false">
+ <span aria-hidden="true" id="apple_id_field_label" class=" form-textbox-label form-label-flyout">
+ Email or Phone Number
+ </span>
+ </div>
+ </div>
\ No newline at end of file