Skip to content

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

Add additional formdetector test (#541)

Leendert de Borstb875fcad4edd
diff --git a/browser-extensions/chrome/src/contentScript.ts b/browser-extensions/chrome/src/contentScript.ts
index 59f3caa72..eb7e78dc5 100644
--- a/browser-extensions/chrome/src/contentScript.ts
+++ b/browser-extensions/chrome/src/contentScript.ts
@@ -758,7 +758,7 @@ function injectIcons(): void {
forms.forEach(form => {
// Determine which field to attach the icon to
- const targetField = form.usernameField || form.passwordField;
+ const targetField = form.emailField || form.usernameField || form.passwordField;
if (targetField && !targetField.parentElement?.querySelector('.aliasvault-input-icon')) {
const wrapper = document.createElement('div');
diff --git a/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts b/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
index b31a249d2..23b9aa364 100644
--- a/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
+++ b/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
@@ -47,7 +47,7 @@ export class FormDetector {
const form = passwordField.closest('form');
// Find all the required fields
- const emailField = this.findInputField(form, ['email'], ['email']);
+ const emailField = this.findEmailField(passwordField);
const usernameField = this.findUsernameField(passwordField);
const passwordConfirmField = this.findPasswordConfirmField(passwordField);
@@ -142,11 +142,44 @@ export class FormDetector {
? form.querySelectorAll<HTMLInputElement>('input')
: this.document.querySelectorAll<HTMLInputElement>('input');
+ for (const input of Array.from(candidates)) {
+ if (input === passwordField) continue;
+
+ const type = input.type.toLowerCase();
+ if (type === 'text') {
+ const attributes = [
+ input.type,
+ input.id,
+ input.name,
+ input.className,
+ input.placeholder
+ ].map(attr => attr?.toLowerCase() || '');
+
+ const patterns = ['user', 'username', 'login', 'identifier'];
+ if (patterns.some(pattern => attributes.some(attr => attr.includes(pattern)))) {
+ return input;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Find the email field in the form containing the password field.
+ */
+ private findEmailField(passwordField: HTMLInputElement): HTMLInputElement | null {
+ const form = passwordField.closest('form');
+ const candidates = form
+ ? form.querySelectorAll<HTMLInputElement>('input')
+ : this.document.querySelectorAll<HTMLInputElement>('input');
+
for (const input of Array.from(candidates)) {
if (input === passwordField) continue;
const type = input.type.toLowerCase();
if (type === 'text' || type === 'email') {
+ // Check input attributes
const attributes = [
input.type,
input.id,
@@ -155,7 +188,21 @@ export class FormDetector {
input.placeholder
].map(attr => attr?.toLowerCase() || '');
- const patterns = ['user', 'username', 'mail', 'email', 'login', 'identifier'];
+ const patterns = ['email', 'e-mail', 'mail', 'address', '@'];
+
+ // Check parent div for email-related text
+ const parentDiv = input.closest('div');
+ if (parentDiv) {
+ const parentText = parentDiv.textContent?.toLowerCase() || '';
+ attributes.push(parentText);
+
+ // Check for label elements within the parent div
+ const labels = parentDiv.getElementsByTagName('label');
+ for (const label of Array.from(labels)) {
+ attributes.push(label.textContent?.toLowerCase() || '');
+ }
+ }
+
if (patterns.some(pattern => attributes.some(attr => attr.includes(pattern)))) {
return input;
}
diff --git a/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts b/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
index e2c9143e3..6dc813cd6 100644
--- a/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
+++ b/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
@@ -104,4 +104,11 @@ describe('FormDetector', () => {
testField(FormField.GenderFemale, 'vrouw', htmlFile);
testField(FormField.GenderOther, 'iets', htmlFile);
});
+
+ describe('English registration form 1 detection', () => {
+ const htmlFile = 'en-registration-form1.html';
+
+ testField(FormField.Email, 'login', htmlFile);
+ testField(FormField.Password, 'password', htmlFile);
+ });
});
\ No newline at end of file
diff --git a/browser-extensions/chrome/src/utils/form-detector/__tests__/test-forms/en-registration-form1.html b/browser-extensions/chrome/src/utils/form-detector/__tests__/test-forms/en-registration-form1.html
new file mode 100644
index 000000000..9d7ae925f
--- /dev/null
+++ b/browser-extensions/chrome/src/utils/form-detector/__tests__/test-forms/en-registration-form1.html
@@ -0,0 +1,15 @@
+<div class="MrRiXf6"><form class=""><section class="flex flex-col sNhHqjk"><section class="WgRVsyT m-b-24"><section class="DBrYv_V"><h4 class="Z75qIDe">Continue with your email</h4></section><div class="field"><section class="field-label"><label for="login">Email</label></section><div class="yyUbhpn cUkPF7r field-input-wrapper invalid"><div class="hXBbl9K"><div style="position: relative; display: inline-block; width: 100%;"><input class="ttjkrx6 field-input" type="text" data-lpignore="true" placeholder="[email protected]" id="login" name="user_session[login]" autocomplete="email" value="dgreen81" style="width: 357.5px; display: inline-block;"><div class="aliasvault-input-icon" style="
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: absolute;
+ right: 8px;
+ top: 8px;
+ margin: auto;
+ cursor: pointer;
+ width: 20px;
+ height: 20px;
+ z-index: 999999;
+ ">
+ <img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA1MDAgNTAwIiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCA1MDAgNTAwIiB4bWw6c3BhY2U9InByZXNlcnZlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJtNDU5Ljg3IDI5NC45NWMwLjAxNjIwNSA1LjQwMDUgMC4wMzI0MSAxMC44MDEtMC4zNTAyMiAxNi44NzMtMS4xMTEgNi4zMzkyLTEuMTk0MSAxMi4xNzMtMi42MzUxIDE3LjY0OS0xMC45MjIgNDEuNTA4LTM2LjczMSA2OS40ODEtNzcuMzUxIDgzLjQwOC03LjIxNTcgMi40NzM5LTE0Ljk3MiAzLjM3MDItMjIuNDc5IDQuOTk1LTIzLjYyOSAwLjA0MjIwNS00Ny4yNTcgMC4xMTQ1My03MC44ODYgMC4xMjAyNy00Ni43NjIgMC4wMTEzMjItOTMuNTIzLTAuMDE0MTYtMTQw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zktMTMuNDk0IDIzLjcwMy01LjI3MiAyLjExNjItMTAuMDkxIDEuNTA4Ni0xNS40NiAwLjAxNzg4M3oiIGZpbGw9IiNFRUMxNzAiLz4KPC9zdmc+" style="width: 100%; height: 100%;">
+ </div></div><span class="glAQDp5 LTPJ6PZ field-input-icon" aria-hidden="true" style="width: 16px; height: 16px;"><svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M8 0C3.6 0 0 3.6 0 8C0 12.4 3.6 16 8 16C12.4 16 16 12.4 16 8C16 3.6 12.4 0 8 0ZM8 12C7.4 12 7 11.6 7 11C7 10.4 7.4 10 8 10C8.6 10 9 10.4 9 11C9 11.6 8.6 12 8 12ZM9 9H7V4H9V9Z"></path></svg></span></div></div><p class="field-error text-body-2">Looks like this email is incomplete</p></div><div class="field IhbFUXL"><section class="field-label"><label for="password">Password</label></section><div class="yyUbhpn cUkPF7r field-input-wrapper"><div class="hXBbl9K"><input class="ttjkrx6 field-input" type="password" data-lpignore="true" placeholder="" id="password" name="user_session[password]" autocomplete="current-password" value="=8O=vkEelbRQsWr-4Y"><button class="glAQDp5 _Q5OMo2 LTPJ6PZ field-input-icon" type="button" style="width: 16px; height: 16px;"><svg width="15" height="12" xmlns="http://www.w3.org/2000/svg"><path d="M14.8594 11.0391L0.843735 0.0822657C0.805293 0.0514871 0.761164 0.0285818 0.71387 0.0148574C0.666575 0.00113296 0.61704 -0.00314169 0.568094 0.00227748C0.519147 0.00769665 0.471747 0.0227035 0.4286 0.0464412C0.385453 0.0701789 0.347404 0.102183 0.316626 0.140625L0.0822505 0.433359C0.0513997 0.471815 0.0284346 0.515976 0.0146694 0.563317C0.000904094 0.610657 -0.00339118 0.660248 0.00202933 0.70925C0.00744984 0.758252 0.0224797 0.805705 0.046259 0.848892C0.0700383 0.892079 0.1021 0.930154 0.14061 0.960937L14.1562 11.9177C14.1947 11.9485 14.2388 11.9714 14.2861 11.9851C14.3334 11.9989 14.3829 12.0031 14.4319 11.9977C14.4808 11.9923 14.5282 11.9773 14.5714 11.9536C14.6145 11.9298 14.6526 11.8978 14.6833 11.8594L14.9177 11.5666C14.9486 11.5282 14.9715 11.484 14.9853 11.4367C14.9991 11.3893 15.0034 11.3397 14.9979 11.2907C14.9925 11.2417 14.9775 11.1943 14.9537 11.1511C14.9299 11.1079 14.8979 11.0698 14.8594 11.0391ZM6.956 3.43289L10.1151 5.90273C10.0631 4.49789 8.91749 3.375 7.49999 3.375C7.31714 3.37534 7.13483 3.39474 6.956 3.43289ZM8.04397 8.56734L4.88483 6.0975C4.93709 7.50211 6.08272 8.625 7.49999 8.625C7.68282 8.62461 7.86512 8.60528 8.04397 8.56734ZM7.49999 2.625C9.8121 2.625 11.9318 3.91406 13.0765 6C12.7959 6.51336 12.4492 6.98772 12.0452 7.41093L12.9298 8.10234C13.4222 7.57551 13.8395 6.9831 14.1696 6.34195C14.2232 6.23589 14.2511 6.11872 14.2511 5.99988C14.2511 5.88104 14.2232 5.76387 14.1696 5.65781C12.8974 3.17789 10.3812 1.5 7.49999 1.5C6.63983 1.5 5.81928 1.66406 5.04772 1.94086L6.13545 2.7914C6.57936 2.69062 7.03405 2.625 7.49999 2.625ZM7.49999 9.375C5.18788 9.375 3.06842 8.08593 1.9235 6C2.20447 5.48663 2.55157 5.01235 2.95592 4.58929L2.07139 3.89789C1.579 4.42464 1.16185 5.01697 0.831782 5.65804C0.778167 5.7641 0.750232 5.88128 0.750232 6.00011C0.750232 6.11895 0.778167 6.23613 0.831782 6.34218C2.1028 8.8221 4.61905 10.5 7.49999 10.5C8.36014 10.5 9.18069 10.3348 9.95225 10.0591L8.86452 9.20882C8.42061 9.30937 7.96616 9.375 7.49999 9.375Z"></path></svg></button></div></div></div></section><section class="flex flex-col flex-justify-end EJOXDmL FBRr7pW"><button class="sPdE5j4 FmssW6b co-grey-600 rP6Aftu JoowYoV LXdbb1D bLW6XzH bg-co-grey-200" disabled="" type="submit"><p>Continue</p></button><p class="tbody-7 co-text-medium S_brCsT">By joining, you agree to the <a class="hWzdbbC" href="/terms_of_service?store=false" target="_blank" rel="noreferrer noopener">Terms of Service</a> and to occasionally receive emails from us. Please read our <a class="hWzdbbC" href="/privacy-policy?store=false" target="_blank" rel="noreferrer noopener">Privacy Policy</a> to learn how we use your personal data.</p></section></section></form></div>
\ No newline at end of file