Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Improve email detection (#541)
Leendert de Borst8c132f30fb9e
diff --git a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts b/browser-extensions/chrome/src/shared/formDetector/FormDetector.tsindex 66b95fed2..061af4f60 100644--- a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts+++ b/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts@@ -198,64 +198,21 @@ export class FormDetector {primary: HTMLInputElement | null,confirm: HTMLInputElement | null} {- const candidates = form- ? form.querySelectorAll<HTMLInputElement>('input')- : this.document.querySelectorAll<HTMLInputElement>('input');-- let primaryEmail: HTMLInputElement | null = null;- let confirmEmail: HTMLInputElement | null = null;-- /**- * Check if an input is an email field.- */- const isEmailField = (input: HTMLInputElement, confirmPatterns: string[] = []): boolean => {- const type = input.type.toLowerCase();- if (type === 'text' || type === 'email') {- const attributes = [- input.type,- input.id,- input.name,- input.className,- input.placeholder- ].map(attr => attr?.toLowerCase() || '');-- // 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() || '');- }- }-- const patterns = [...confirmPatterns, 'email', 'e-mail', 'mail', 'address', '@'];- return patterns.some(pattern => attributes.some(attr => attr.includes(pattern)));- }- return false;- };-- // First pass: find primary email- for (const input of Array.from(candidates)) {- if (!primaryEmail && isEmailField(input)) {- primaryEmail = input;- break;- }- }+ // Find primary email field+ const primaryEmail = this.findInputField(+ form,+ ['email', 'e-mail', 'mail', 'address', '@'],+ ['text', 'email']+ );- // Second pass: find confirmation email- if (primaryEmail) {- for (const input of Array.from(candidates)) {- if (input !== primaryEmail &&- isEmailField(input, ['confirm', 'verification', 'repeat', 'retype', 'verify'])) {- confirmEmail = input;- break;- }- }- }+ // Find confirmation email field if primary exists+ const confirmEmail = primaryEmail+ ? this.findInputField(+ form,+ ['confirm', 'verification', 'repeat', 'retype', 'verify'],+ ['text', 'email']+ )+ : null;return {primary: primaryEmail,diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.tsindex 55a6d316c..d17b21daf 100644--- a/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/FormDetector.nl.test.ts@@ -57,4 +57,13 @@ describe('FormDetector', () => {testField(FormField.BirthDate, 'input_25_10', htmlFile);testBirthdateFormat('dd/mm/yyyy', htmlFile);});++ describe('Dutch registration form 6 detection', () => {+ const htmlFile = 'nl-registration-form6.html';++ testField(FormField.Email, 'field18478', htmlFile);+ testField(FormField.FirstName, 'field18479', htmlFile);+ testField(FormField.LastName, 'field18486', htmlFile);++ });});diff --git a/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form6.html b/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form6.htmlnew file mode 100644index 000000000..084f2621c--- /dev/null+++ b/browser-extensions/chrome/src/shared/formDetector/__tests__/test-forms/nl-registration-form6.html@@ -0,0 +1,69 @@+<form id="form11501" enctype="application/x-www-form-urlencoded" class="mpForm" method="post" action="" novalidate="novalidate">+ <table class="mpFormTable mpTwoColumnLayout">+ <tbody><tr>+ <td>+ <table id="CNT18485" role="group" class="mpQuestionTable error inlineValidated" aria-labelledby="lbl-field18485">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18485" id="lbl-field18485">Graag ontvang ik (meerdere opties mogelijk):</label><span class="mandatorySign"> *</span></td>+ <td class="mpFormField">+ <ul id="field18485">+ <li><input type="checkbox" value="2" id="field18485-2011" name="field18485" aria-labelledby="lbl-field18485 field18485-2011" class="mpMultipleInput" autocomplete="false" aria-invalid="true"><label class="mpMultipleLabel" for="field18485-2011">De nieuwsbrief voor vrijwilligerswerk</label></li>+ <li><input type="checkbox" value="4" id="field18485-2010" name="field18485" aria-labelledby="lbl-field18485 field18485-2010" class="mpMultipleInput" aria-invalid="true"><label class="mpMultipleLabel" for="field18485-2010">De nieuwsbrief voor mantelzorgers</label></li>+ </ul>+ </td>+ </tr>+ <tr class="mpErrorRow"><td colspan="2"><label id="field18485-error" class="error" for="field18485">Maak a.u.b. een keuze.</label></td></tr></tbody></table>+ <table id="CNT18478" role="group" class="mpQuestionTable error inlineValidated" aria-labelledby="lbl-field18478">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18478" id="lbl-field18478">E-mailadres</label><span class="mandatorySign"> *</span></td>+ <td class="mpFormField"><input type="text" id="field18478" name="field18478" autocomplete="false" aria-invalid="true"><div class="sublabel">[email protected] </div>+ </td>+ </tr>+ <tr class="mpErrorRow"><td colspan="2"><label id="field18478-error" class="error" for="field18478">Vul a.u.b. een e-mailadres in.</label></td></tr></tbody></table>+ <table id="CNT18477" role="group" class="mpQuestionTable " aria-labelledby="lbl-field18477" style="display: none;">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18477" id="lbl-field18477">Email</label></td>+ <td class="mpFormField"><input type="text" id="field18477" name="field18477"></td>+ </tr>+ </tbody></table>+ <table id="CNT18479" role="group" class="mpQuestionTable mpHighlight" aria-labelledby="lbl-field18479">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18479" id="lbl-field18479">Voornaam</label></td>+ <td class="mpFormField"><input type="text" id="field18479" name="field18479" autocomplete="false" aria-invalid="false"></td>+ </tr>+ </tbody></table>+ <table id="CNT18476" role="group" class="mpQuestionTable " aria-labelledby="lbl-field18476" style="display: none;">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18476" id="lbl-field18476">0 + 1 =</label><span class="mandatorySign"> *</span></td>+ <td class="mpFormField"><input type="text" id="field18476" name="field18476" value="1"></td>+ </tr>+ </tbody></table>+ <table id="CNT18486" role="group" class="mpQuestionTable " aria-labelledby="lbl-field18486">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18486" id="lbl-field18486">Achternaam</label></td>+ <td class="mpFormField"><input type="text" id="field18486" name="field18486" autocomplete="family-name"></td>+ </tr>+ </tbody></table>+ <table id="CNT18487" role="group" class="mpQuestionTable" aria-labelledby="lbl-field18487">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18487" id="lbl-field18487">Organisatie (indien van toepassing)</label></td>+ <td class="mpFormField"><input type="text" id="field18487" name="field18487" autocomplete="false"></td>+ </tr>+ </tbody></table>+ <table id="CNT18975" role="group" class="mpQuestionTable " aria-labelledby="lbl-field18975">+ <tbody><tr class="mpLabelRow">+ <td class="mpFormLabel"><label class="descriptionLabel" for="field18975" id="lbl-field18975">Mobiel</label></td>+ <td class="mpFormField"><input type="text" maxlength="15" size="15" id="field18975" name="field18975" autocomplete="tel"></td>+ </tr>+ </tbody></table>+ <table id="CNT18484" role="group" class="mpQuestionTable " aria-labelledby="lbl-field18484">+ <tbody><tr class="mpLabelRow">+ <td class="submitCellSpacer"><span></span></td>+ <td class="submitCell"><input value="Aanmelden" class="submitButton" name="next" type="submit" id="field18484"></td>+ </tr>+ </tbody></table>+ </td>+ </tr>+ </tbody></table>+ <fieldset style="display: none"><input type="hidden" name="userId" value="314100103"><input type="hidden" name="formEncId" value="zdXwzQtKhCXtthgkjsuU"><input type="hidden" name="pageEncId" value="ze4Nb47CgT"><input type="hidden" name="paramActivityId" value="test"><input type="hidden" name="subscriptionEncId" value="{encId}"><input type="hidden" name="pagePosition" value="1"><input type="hidden" name="viewMode" value="LANDINGPAGE"><input type="hidden" name="redir" value="formAdmin2"><input type="hidden" name="formLayout" value="N"><input type="hidden" name="errorText" value="Dit formulier kon niet verzonden worden om de volgende reden(en):"><input type="hidden" name="abInfo" value="04eRNBA4/P0QrJR3bDHX8IOU5u2iLw/xAd74Rxw+E7LuscXwaOlQrjOfO7+gJdAVHMxnHKcCMVAGg4t6SVd/n037kaaIrZFr2u7Sc6TN7HV+ObQHFQYKwbjD02LchIyKsdr4clKYJw+nnO5FORREwBu4rY/eIyQ5XmJAild5UviN4gUwAW6o6TszkS+/Nh3H"></fieldset>+ </form>\ No newline at end of file