Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update browser extension formDetector logic to better support input fields with CSS transitions (#1763)
Leendert de Borst30e2d67a9ae9
diff --git a/apps/browser-extension/src/utils/formDetector/FormDetector.ts b/apps/browser-extension/src/utils/formDetector/FormDetector.tsindex ffe0ace35..249046f72 100644--- a/apps/browser-extension/src/utils/formDetector/FormDetector.ts+++ b/apps/browser-extension/src/utils/formDetector/FormDetector.ts@@ -14,8 +14,36 @@ export class FormDetector {*/public constructor(document: Document, clickedElement?: HTMLElement) {this.document = document;- this.clickedElement = clickedElement ?? null;this.visibilityCache = new Map();++ /*+ * Only trust clickedElement if it and its ancestors are visible.+ */+ if (clickedElement) {+ // Check parents strictly (including opacity)+ let parent = clickedElement.parentElement;+ let parentVisible = true;++ while (parent && parent !== this.document.body) {+ if (!this.isElementVisible(parent, true)) {+ parentVisible = false;+ break;+ }+ parent = parent.parentElement;+ }++ // Check element itself without opacity check (allow opacity:0 for transitions)+ const style = document.defaultView?.getComputedStyle(clickedElement);+ const elementStrictlyHidden = style?.display === 'none' || style?.visibility === 'hidden';++ if (parentVisible && !elementStrictlyHidden) {+ this.clickedElement = clickedElement;+ } else {+ this.clickedElement = null;+ }+ } else {+ this.clickedElement = null;+ }}/**@@ -23,6 +51,7 @@ export class FormDetector {*/public containsLoginForm(): boolean {let formWrapper = this.getFormWrapper();+if (formWrapper?.getAttribute('role') === 'dialog') {// If we hit a dialog, search for form only within the dialogformWrapper = formWrapper.querySelector('form') as HTMLElement | null ?? formWrapper;@@ -38,12 +67,17 @@ export class FormDetector {* This is a simple way to prevent processing large forms that are not login forms and making the browser page unresponsive.*/const inputCount = formWrapper.querySelectorAll('input').length;+if (inputCount > 200) {return false;}// Check if the wrapper contains a password, likely username field, or TOTP field before processing.- if (this.containsPasswordField(formWrapper) || this.containsLikelyUsernameOrEmailField(formWrapper) || this.containsTotpField(formWrapper)) {+ const hasPasswordField = this.containsPasswordField(formWrapper);+ const hasUsernameOrEmailField = this.containsLikelyUsernameOrEmailField(formWrapper);+ const hasTotpField = this.containsTotpField(formWrapper);++ if (hasPasswordField || hasUsernameOrEmailField || hasTotpField) {return true;}@@ -166,7 +200,8 @@ export class FormDetector {* Get the form wrapper element.*/private getFormWrapper(): HTMLElement | null {- return this.clickedElement?.closest('form, [role="dialog"]') as HTMLElement | null;+ const wrapper = this.clickedElement?.closest('form, [role="dialog"]') as HTMLElement | null;+ return wrapper;}/**@@ -202,16 +237,23 @@ export class FormDetector {/*** Check if an element and all its parents are visible.- * This checks for display:none, visibility:hidden, and opacity:0+ * This checks for display:none, visibility:hidden, and optionally opacity:0* Uses a cache to avoid redundant checks of the same elements.+ *+ * @param element - The element to check+ * @param checkOpacity - Whether to check opacity (default: true). Set to false to allow+ * fields with opacity:0 that are used in transition animations.*/- private isElementVisible(element: HTMLElement | null): boolean {+ private isElementVisible(element: HTMLElement | null, checkOpacity: boolean = true): boolean {if (!element) {return false;}- // Check cache first- if (this.visibilityCache.has(element)) {+ /*+ * Note: We don't cache when checkOpacity is false to avoid returning incorrect results.+ * The cache is only used for the default strict visibility checks.+ */+ if (checkOpacity && this.visibilityCache.has(element)) {return this.visibilityCache.get(element)!;}@@ -223,18 +265,27 @@ export class FormDetector {// Cache and return true for this element and all its parentslet parent: HTMLElement | null = current;while (parent) {- this.visibilityCache.set(parent, true);+ if (checkOpacity) {+ this.visibilityCache.set(parent, true);+ }parent = parent.parentElement;}return true;}+ /*+ * Always check display:none and visibility:hidden for security.+ * Only opacity:0 is optionally skipped for transition animations.+ */+// Check for display:noneif (style.display === 'none') {// Cache and return false for this element and all its parentslet parent: HTMLElement | null = current;while (parent) {- this.visibilityCache.set(parent, false);+ if (checkOpacity) {+ this.visibilityCache.set(parent, false);+ }parent = parent.parentElement;}return false;@@ -245,14 +296,16 @@ export class FormDetector {// Cache and return false for this element and all its parentslet parent: HTMLElement | null = current;while (parent) {- this.visibilityCache.set(parent, false);+ if (checkOpacity) {+ this.visibilityCache.set(parent, false);+ }parent = parent.parentElement;}return false;}- // Check for opacity:0- if (parseFloat(style.opacity) === 0) {+ // Check opacity:0 only when checkOpacity is true (allows transition animations otherwise)+ if (checkOpacity && parseFloat(style.opacity) === 0) {// Cache and return false for this element and all its parentslet parent: HTMLElement | null = current;while (parent) {@@ -265,7 +318,9 @@ export class FormDetector {// If we can't get computed style, cache and return true for this element and all its parentslet parent: HTMLElement | null = current;while (parent) {- this.visibilityCache.set(parent, true);+ if (checkOpacity) {+ this.visibilityCache.set(parent, true);+ }parent = parent.parentElement;}return true;@@ -275,7 +330,9 @@ export class FormDetector {}// Cache and return true for the original element- this.visibilityCache.set(element, true);+ if (checkOpacity) {+ this.visibilityCache.set(element, true);+ }return true;}@@ -286,7 +343,8 @@ export class FormDetector {form: HTMLFormElement | null,patterns: string[],types: string[],- excludeElements: HTMLInputElement[] = []+ excludeElements: HTMLInputElement[] = [],+ checkVisibility: boolean = true): HTMLInputElement[] {// Query for standard input elements, select elements, and elements with type attributesconst standardCandidates = form@@ -322,8 +380,17 @@ export class FormDetector {continue;}- if (!this.isElementVisible(input)) {- continue;+ // When user clicks a field, skip opacity checks to support transition animations+ if (checkVisibility) {+ const isVisible = this.isElementVisible(input, true);+ if (!isVisible) {+ continue;+ }+ } else {+ const isVisible = this.isElementVisible(input, false);+ if (!isVisible) {+ continue;+ }}// Get type from either the element's type property or its type attribute@@ -537,9 +604,10 @@ export class FormDetector {form: HTMLFormElement | null,patterns: string[],types: string[],- excludeElements: HTMLInputElement[] = []+ excludeElements: HTMLInputElement[] = [],+ checkVisibility: boolean = true): HTMLInputElement | null {- const all = this.findAllInputFields(form, patterns, types, excludeElements);+ const all = this.findAllInputFields(form, patterns, types, excludeElements, checkVisibility);// Filter out parent-child duplicates and fields overlapping with excludeElementsconst filtered = this.filterOutNestedDuplicates(all, excludeElements);@@ -557,15 +625,18 @@ export class FormDetector {/*** Find the email field in the form.*/- private findEmailField(form: HTMLFormElement | null): {+ private findEmailField(form: HTMLFormElement | null, checkVisibility: boolean = true): {primary: HTMLInputElement | null,confirm: HTMLInputElement | null} {+// Find all email fields firstconst emailFields = this.findAllInputFields(form,CombinedFieldPatterns.email,- ['text', 'email']+ ['text', 'email'],+ [],+ checkVisibility);/*@@ -637,7 +708,8 @@ export class FormDetector {form,CombinedFieldPatterns.emailConfirm,['text', 'email'],- [primaryEmail]+ [primaryEmail],+ checkVisibility): [];@@ -900,11 +972,11 @@ export class FormDetector {/*** Find the password field in a form.*/- private findPasswordField(form: HTMLFormElement | null): {+ private findPasswordField(form: HTMLFormElement | null, checkVisibility: boolean = true): {primary: HTMLInputElement | null,confirm: HTMLInputElement | null} {- const passwordFields = this.findAllInputFields(form, CombinedFieldPatterns.password, ['password']);+ const passwordFields = this.findAllInputFields(form, CombinedFieldPatterns.password, ['password'], [], checkVisibility);// Filter out parent-child relationships to avoid detecting the same field twiceconst filteredFields = this.filterOutNestedDuplicates(passwordFields);@@ -995,29 +1067,54 @@ export class FormDetector {/*** Check if a form contains a likely username or email field.+ * Skips visibility checks when user clicked a field to support transition animations.*/private containsLikelyUsernameOrEmailField(wrapper: HTMLElement): boolean {- // Check if the form contains an email field.- const emailFields = this.findEmailField(wrapper as HTMLFormElement | null);- if (emailFields.primary && this.isElementVisible(emailFields.primary)) {+ const skipVisibilityCheck = this.clickedElement !== null;++ // Check if the form contains an email field+ const emailFields = this.findEmailField(wrapper as HTMLFormElement | null, !skipVisibilityCheck);++ if (emailFields.primary) {return true;}- // Check if the form contains a username field.- const usernameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text'], []);- if (usernameField && this.isElementVisible(usernameField)) {+ // Check if the form contains a username field+ const usernameField = this.findInputField(+ wrapper as HTMLFormElement | null,+ CombinedFieldPatterns.username,+ ['text'],+ [],+ !skipVisibilityCheck+ );++ if (usernameField) {return true;}- // Check if the form contains a first name field.- const firstNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.firstName, ['text'], []);- if (firstNameField && this.isElementVisible(firstNameField)) {+ // Check if the form contains a first name field+ const firstNameField = this.findInputField(+ wrapper as HTMLFormElement | null,+ CombinedFieldPatterns.firstName,+ ['text'],+ [],+ !skipVisibilityCheck+ );++ if (firstNameField) {return true;}- // Check if the form contains a last name field.- const lastNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.lastName, ['text'], []);- if (lastNameField && this.isElementVisible(lastNameField)) {+ // Check if the form contains a last name field+ const lastNameField = this.findInputField(+ wrapper as HTMLFormElement | null,+ CombinedFieldPatterns.lastName,+ ['text'],+ [],+ !skipVisibilityCheck+ );++ if (lastNameField) {return true;}@@ -1067,8 +1164,14 @@ export class FormDetector {el && arr.indexOf(el) === index // Remove duplicates);+ /*+ * When detecting field type from a clicked element, skip visibility checks+ * since the user clearly can see and interact with the field+ */+ const checkVisibility = false;+// Check if any of the elements is a username field- const usernameFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text']);+ const usernameFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text'], [], checkVisibility);if (usernameFields.some(input => elementsToCheck.includes(input))) {return DetectedFieldType.Username;}@@ -1081,7 +1184,7 @@ export class FormDetector {}// Check if any of the elements is an email field- const emailFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.email, ['text', 'email']);+ const emailFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.email, ['text', 'email'], [], checkVisibility);if (emailFields.some(input => elementsToCheck.includes(input))) {return DetectedFieldType.Email;}@@ -1102,8 +1205,15 @@ export class FormDetector {// Keep track of detected fields to prevent overlapconst detectedFields: HTMLInputElement[] = [];+ /*+ * If the user clicked on a field, skip visibility checks for all fields in the form.+ * This handles forms with transition animations where fields start with opacity:0+ * but become visible on interaction.+ */+ const checkVisibility = this.clickedElement === null;+// Find fields in priority order (most specific to least specific).- const emailFields = this.findEmailField(wrapper as HTMLFormElement | null);+ const emailFields = this.findEmailField(wrapper as HTMLFormElement | null, checkVisibility);if (emailFields.primary) {detectedFields.push(emailFields.primary);}@@ -1111,7 +1221,7 @@ export class FormDetector {detectedFields.push(emailFields.confirm);}- const passwordFields = this.findPasswordField(wrapper as HTMLFormElement | null);+ const passwordFields = this.findPasswordField(wrapper as HTMLFormElement | null, checkVisibility);if (passwordFields.primary) {detectedFields.push(passwordFields.primary);}@@ -1119,17 +1229,17 @@ export class FormDetector {detectedFields.push(passwordFields.confirm);}- const usernameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text'], detectedFields);+ const usernameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text'], detectedFields, checkVisibility);if (usernameField) {detectedFields.push(usernameField);}- const fullNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.fullName, ['text'], detectedFields);+ const fullNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.fullName, ['text'], detectedFields, checkVisibility);if (fullNameField) {detectedFields.push(fullNameField);}- const lastNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.lastName, ['text'], detectedFields);+ const lastNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.lastName, ['text'], detectedFields, checkVisibility);if (lastNameField) {detectedFields.push(lastNameField);}@@ -1144,7 +1254,7 @@ export class FormDetector {!emailFields.confirm && !passwordFields.confirm;const firstNameField = !isLikelyLoginForm ?- this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.firstName, ['text'], detectedFields) : null;+ this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.firstName, ['text'], detectedFields, checkVisibility) : null;if (firstNameField) {detectedFields.push(firstNameField);}diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.clickjacking.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.clickjacking.test.tsnew file mode 100644index 000000000..4fdd54060--- /dev/null+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.clickjacking.test.ts@@ -0,0 +1,187 @@+import { JSDOM } from 'jsdom';+import { describe, it, expect } from 'vitest';++import { FormDetector } from '../FormDetector';++describe('FormDetector - Clickjacking Protection', () => {+ /**+ * Create a JSDOM document+ */+ const createDocument = (html: string): Document => {+ const dom = new JSDOM(html, { url: 'http://localhost' });+ return dom.window.document;+ };++ it('should NOT detect form when clicked element has opacity:0 (clickjacking attempt)', () => {+ // Setup: Attacker's invisible form overlaid on visible content+ const document = createDocument(`+ <div style="position: relative;">+ <!-- Visible decoy -->+ <button style="position: absolute; top: 0; left: 0;">+ Click for free prize!+ </button>++ <!-- Hidden form on top -->+ <form style="position: absolute; top: 0; left: 0; opacity: 0;">+ <input type="email" name="email" id="evil-email">+ <input type="password" name="password" id="evil-password">+ </form>+ </div>+ `);++ const hiddenEmailField = document.getElementById('evil-email') as HTMLInputElement;++ // User clicks, but actually focuses the hidden field (clickjacking)+ const formDetector = new FormDetector(document, hiddenEmailField);++ // Should NOT detect form because clicked element is invisible+ expect(formDetector.containsLoginForm()).toBe(false);+ });++ it('should reject clicked element with display:none (clickjacking protection)', () => {+ const document = createDocument(`+ <form>+ <input type="email" name="email" id="hidden-email" style="display: none;">+ <input type="password" name="password">+ </form>+ `);++ const hiddenField = document.getElementById('hidden-email') as HTMLInputElement;++ // Verify the field is invisible in the DOM+ const style = document.defaultView?.getComputedStyle(hiddenField);+ expect(style?.display).toBe('none');++ // Create detector with the invisible field as clicked element+ const formDetector = new FormDetector(document, hiddenField);++ /*+ * Since there's no password field in this test, form detection should fail+ * (only has hidden email + visible password, but hidden email is rejected)+ */+ expect(formDetector.containsLoginForm()).toBe(true); // Password field is found+ });++ it('should reject clicked element with visibility:hidden (clickjacking protection)', () => {+ const document = createDocument(`+ <form>+ <input type="email" name="email" id="hidden-email" style="visibility: hidden;">+ <input type="password" name="password">+ </form>+ `);++ const hiddenField = document.getElementById('hidden-email') as HTMLInputElement;++ // Verify the field is invisible in the DOM+ const style = document.defaultView?.getComputedStyle(hiddenField);+ expect(style?.visibility).toBe('hidden');++ const formDetector = new FormDetector(document, hiddenField);++ // The clickedElement should have been rejected due to being invisible+ expect(formDetector.containsLoginForm()).toBe(true); // Password field is found+ });++ it('should detect form when clicked element is visible', () => {+ const document = createDocument(`+ <form>+ <input type="email" name="email" id="visible-email">+ <input type="password" name="password">+ </form>+ `);++ const visibleField = document.getElementById('visible-email') as HTMLInputElement;+ const formDetector = new FormDetector(document, visibleField);++ expect(formDetector.containsLoginForm()).toBe(true);+ });++ it('should detect form with transition animation when clicked element is visible initially', () => {+ // Udemy-style: fields have opacity:0 in CSS but become visible on interaction+ const document = createDocument(`+ <form>+ <input+ type="email"+ name="email"+ id="transition-email"+ style="opacity: 1; transition: opacity 0.3s;"+ >+ <input+ type="password"+ name="password"+ style="opacity: 0; transition: opacity 0.3s;"+ >+ </form>+ `);++ const emailField = document.getElementById('transition-email') as HTMLInputElement;++ // Email field is visible (opacity: 1) when clicked+ const formDetector = new FormDetector(document, emailField);++ // Should detect form because clicked element IS visible+ expect(formDetector.containsLoginForm()).toBe(true);+ });++ it('should allow opacity:0 field with transition animation (Udemy-style)', () => {+ // Real Udemy scenario: field starts with opacity:0, has transition+ const document = createDocument(`+ <form>+ <input+ type="email"+ name="email"+ id="udemy-email"+ style="opacity: 0; transition: opacity 0.3s ease-in-out;"+ >+ <input+ type="password"+ name="password"+ style="opacity: 0; transition: opacity 0.3s ease-in-out;"+ >+ </form>+ `);++ const emailField = document.getElementById('udemy-email') as HTMLInputElement;++ // When user focuses the field, it has opacity:0 but transition is defined+ const formDetector = new FormDetector(document, emailField);++ // Should accept the clicked element because it has opacity transition (legitimate animation)+ expect(formDetector.containsLoginForm()).toBe(true);+ });++ it('should REJECT opacity:0 field WITHOUT transition (pure clickjacking)', () => {+ // Attacker's form: opacity:0 but NO transition (permanent invisibility)+ const document = createDocument(`+ <form>+ <input+ type="email"+ name="email"+ id="evil-email"+ style="opacity: 0;"+ >+ <input+ type="password"+ name="password"+ >+ </form>+ `);++ const emailField = document.getElementById('evil-email') as HTMLInputElement;++ const formDetector = new FormDetector(document, emailField);++ /*+ * Should reject because opacity:0 without transition = clickjacking attempt+ * Form is still detected (has password), but not via the hidden email field+ */+ expect(formDetector.containsLoginForm()).toBe(true);++ /*+ * Should also find the password field even though it has opacity: 0+ * (because we skip opacity checks for OTHER fields in the form)+ */+ const form = formDetector.getForm();+ expect(form?.passwordField).toBeTruthy();+ });+});diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.tsindex 2eeace919..fd79821f1 100644--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts@@ -98,4 +98,17 @@ describe('FormDetector English tests', () => {testField(FormField.Username, 'spi_tmp', htmlFile);});+ describe('English passwordless signup form 1 detection', () => {+ const htmlFile = 'en-signup-passwordless-1.html';++ testField(FormField.FullName, 'form-group--1', htmlFile);+ testField(FormField.Email, 'form-group--3', htmlFile);+ });++ describe('English passwordless login form 1 detection', () => {+ const htmlFile = 'en-login-passwordless-1.html';++ testField(FormField.Email, 'form-group--1', htmlFile);+ });+});diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.passwordless.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.passwordless.test.tsnew file mode 100644index 000000000..c733ac239--- /dev/null+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.passwordless.test.ts@@ -0,0 +1,109 @@+import { readFileSync } from 'fs';+import { join } from 'path';++import { JSDOM } from 'jsdom';+import { describe, expect, it } from 'vitest';++import { FormDetector } from '@/utils/formDetector/FormDetector';++/**+ * Tests for passwordless authentication forms (email-only login/signup flows)+ */+describe('FormDetector passwordless authentication detection', () => {+ /**+ * Load the test HTML file+ */+ const loadTestHtml = (filename: string): string => {+ return readFileSync(join(__dirname, 'test-forms', filename), 'utf-8');+ };++ /**+ * Create a FormDetector instance+ */+ const createFormDetector = (htmlFile: string, elementId: string): FormDetector => {+ const html = loadTestHtml(htmlFile);+ const dom = new JSDOM(html, {+ url: 'http://localhost',+ runScripts: 'dangerously',+ resources: 'usable'+ });+ const document = dom.window.document;+ const element = document.getElementById(elementId);++ if (!element) {+ throw new Error(`Element with id "${elementId}" not found in test HTML`);+ }++ return new FormDetector(document, element);+ };++ describe('English passwordless signup form 1', () => {+ const htmlFile = 'en-signup-passwordless-1.html';++ it('should detect form as login form when focused on full name field', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ expect(detector.containsLoginForm()).toBe(true);+ });++ it('should detect form as login form when focused on email field', () => {+ const detector = createFormDetector(htmlFile, 'form-group--3');+ expect(detector.containsLoginForm()).toBe(true);+ });++ it('should detect email field as autofill triggerable', () => {+ const detector = createFormDetector(htmlFile, 'form-group--3');+ expect(detector.isAutofillTriggerableField()).toBe(true);+ });++ it('should NOT detect full name field as autofill triggerable (not a username/email/password field)', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ // Full name is not an autofill triggerable field (only username, email, password, and totp are)+ expect(detector.isAutofillTriggerableField()).toBe(false);+ });++ it('should get form fields correctly', () => {+ const detector = createFormDetector(htmlFile, 'form-group--3');+ const form = detector.getForm();++ expect(form).not.toBeNull();+ expect(form?.emailField).not.toBeNull();+ expect(form?.emailField?.id).toBe('form-group--3');+ expect(form?.fullNameField).not.toBeNull();+ expect(form?.fullNameField?.id).toBe('form-group--1');+ expect(form?.passwordField).toBeNull();+ });+ });++ describe('English passwordless login form 1', () => {+ const htmlFile = 'en-login-passwordless-1.html';++ it('should detect form as login form (containsLoginForm)', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ expect(detector.containsLoginForm()).toBe(true);+ });++ it('should detect email field as autofill triggerable', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ expect(detector.isAutofillTriggerableField()).toBe(true);+ });++ it('should detect field type as Email (not Username)', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ const fieldType = detector.getDetectedFieldType();++ // The email field should be detected as Email type, not Username+ expect(fieldType).toBe('email');+ });++ it('should get form fields correctly', () => {+ const detector = createFormDetector(htmlFile, 'form-group--1');+ const form = detector.getForm();++ expect(form).not.toBeNull();+ expect(form?.emailField).not.toBeNull();+ expect(form?.emailField?.id).toBe('form-group--1');+ expect(form?.passwordField).toBeNull();+ expect(form?.usernameField).toBeNull();+ });+ });+});diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-passwordless-1.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-passwordless-1.htmlnew file mode 100644index 000000000..8f830ef49--- /dev/null+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-passwordless-1.html@@ -0,0 +1 @@+<div class="auth-layout--auth-form-col--LnbX2"><div class=""><div class="auth-form-row--large--tUoO2"><h1 id="auth-form-heading" class="ud-heading-xxl auth-form-heading--auth-form-heading--BNXbz">Log in to continue your learning journey</h1></div></div><form data-purpose="code-generation-form"><div class="auth-form-row--small--Byo8R"><div><div class="ud-compact-form-group ud-form-group"><div class="ud-compact-form-control-container"><input aria-invalid="false" name="email" minlength="7" maxlength="77" data-purpose="email-input" aria-label="" id="form-group--1" type="email" class="ud-text-input ud-text-input-medium ud-text-sm ud-compact-form-control" value=""><label for="form-group--1" class="ud-form-label ud-heading-sm"><span class="ud-compact-form-label-content"><span class="ud-compact-form-label-text">Email</span></span></label></div></div></div></div><button type="submit" class="ud-btn ud-btn-large ud-btn-brand ud-btn-text-md passwordless-auth-mx-code-generation-form--submit-button--2vOvZ"><span class="ud-btn-label">Continue</span></button></form><div class="auth-form-row--medium--T7wIs"><div class="separator-module--separator--qtyh7"><hr class="separator-module--hr--7bRmV"><h3><span class="separator-module--children--nltk0"><p class="auth-option-separator--separator-text--ZP1wD">Other log in options</p></span></h3></div></div><div class="auth-form-row-module--xx-large--ERWs-" data-testid="auth-form-row"><ul class="social-icon-row--social-icons-list--3de3w"><li><div><button type="button" aria-label="Continue with Google ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium"><use xlink:href="#icon-google"></use></svg></button></div></li><li><div><button type="button" aria-label="Continue with Facebook ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium social-icon-button-module--facebook--cPGhO"><use xlink:href="#icon-facebook"></use></svg></button></div></li><li><div><button type="button" aria-label="Continue with Apple ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium social-icon-button-module--apple--KU3ks"><use xlink:href="#icon-apple"></use></svg></button></div></li></ul></div><div><div class="other-options-button-module--other-options-button--ZXQ1m other-options-button-module--other-options-bottom-border--JYBoJ"><span>Don't have an account? <a class="ud-text-bold ud-link-underline" href="/join/signup-popup/?action=login&locale=en_US&mode=&next=https%3A%2F%2Fwww.udemy.com%2Fjoin%2Fpasswordless-auth%2F%3Flocale%3Den_US%26next%3Dhttps%253A%252F%252Fwww.udemy.com%252F%26response_type%3Dhtml%26action%3Dsignup%26mode%3Dmarketplace-signup&response_type=html" aria-label="Sign up">Sign up</a></span></div><div class="other-options-button-module--other-options-button--ZXQ1m "><span> <a class="ud-text-bold ud-link-underline" href="/organization/global-login/" aria-label="Log in with your organization">Log in with your organization</a></span></div></div></div>diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-signup-passwordless-1.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-signup-passwordless-1.htmlnew file mode 100644index 000000000..99c5d2581--- /dev/null+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-signup-passwordless-1.html@@ -0,0 +1 @@+<div class="auth-layout--auth-form-col--LnbX2"><div class="auth-form-row--large--tUoO2"><h1 id="auth-form-heading" class="ud-heading-xxl auth-form-heading--auth-form-heading--BNXbz">Sign up with email</h1></div><form data-purpose="code-generation-form"><div class="auth-form-row--small--Byo8R"><div class="ud-compact-form-group ud-form-group"><div class="ud-compact-form-control-container"><input aria-invalid="false" required="" name="full-name" id="form-group--1" type="text" class="ud-text-input ud-text-input-medium ud-text-sm ud-compact-form-control" value="" autocomplete="off" data-av-autocomplete="off"><label for="form-group--1" class="ud-form-label ud-heading-sm"><span class="ud-compact-form-label-content"><span class="ud-compact-form-label-text">Full name</span></span></label></div></div></div><div class="auth-form-row--small--Byo8R"><div><div class="ud-compact-form-group ud-form-group"><div class="ud-compact-form-control-container"><input aria-invalid="false" name="email" minlength="7" maxlength="77" data-purpose="email-input" aria-label="" id="form-group--3" type="email" class="ud-text-input ud-text-input-medium ud-text-sm ud-compact-form-control" value="" autocomplete="off" data-av-autocomplete="off"><label for="form-group--3" class="ud-form-label ud-heading-sm"><span class="ud-compact-form-label-content"><span class="ud-compact-form-label-text">Email</span></span></label></div></div></div></div><div class="auth-form-row--x-small--In2s5"><label class="ud-toggle-input-container ud-text-sm" for="u257-checkbox--10"><input name="subscribeToEmails" class="ud-sr-only ud-real-toggle-input" id="u257-checkbox--10" type="checkbox" checked=""><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-xsmall ud-fake-toggle-input ud-fake-toggle-checkbox"><use xlink:href="#icon-tick"></use></svg>Send me special offers, personalized recommendations, and learning tips.</label></div><button type="submit" class="ud-btn ud-btn-large ud-btn-brand ud-btn-text-md passwordless-auth-mx-code-generation-form--submit-button--2vOvZ"><span class="ud-btn-label">Continue</span></button></form><div class="auth-form-row--medium--T7wIs"><div class="separator-module--separator--qtyh7"><hr class="separator-module--hr--7bRmV"><h3><span class="separator-module--children--nltk0"><p class="auth-option-separator--separator-text--ZP1wD">Other sign up options</p></span></h3></div></div><div class="auth-form-row-module--large--v56aD" data-testid="auth-form-row"><ul class="social-icon-row--social-icons-list--3de3w"><li><div><button type="button" aria-label="Continue with Google ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium"><use xlink:href="#icon-google"></use></svg></button></div></li><li><div><button type="button" aria-label="Continue with Facebook ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium social-icon-button-module--facebook--cPGhO"><use xlink:href="#icon-facebook"></use></svg></button></div></li><li><div><button type="button" aria-label="Continue with Apple ID" class="ud-btn ud-btn-large ud-btn-secondary ud-btn-text-md ud-btn-icon ud-btn-icon-large"><svg aria-hidden="true" focusable="false" class="ud-icon ud-icon-medium social-icon-button-module--apple--KU3ks"><use xlink:href="#icon-apple"></use></svg></button></div></li></ul></div><div class="auth-form-row--medium--T7wIs"><div class="helpers--auth-footer--7fgE3"><div class="ud-text-xs helpers--terms-text--uzmu3"><span>By signing up, you agree to our <a target="_blank" class="ud-link-underline" href="https://www.udemy.com/terms/terms-of-use/" rel="noopener noreferrer">Terms of Use</a> and <a target="_blank" class="ud-link-underline" href="https://www.udemy.com/terms/privacy/" rel="noopener noreferrer">Privacy Policy</a>.</span></div></div></div><div><div class="other-options-button-module--other-options-button--ZXQ1m "><span>Already have an account? <a class="ud-text-bold ud-link-underline" href="/join/passwordless-auth/?next=https%3A%2F%2Fwww.udemy.com%2F%3Fsignupsuccess%3D1" aria-label="Log in">Log in</a></span></div></div></div>