Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Improve browser extension autofill trigger to work on more websites (#1620)
Leendert de Borst1367bd343909
diff --git a/apps/browser-extension/src/entrypoints/content.ts b/apps/browser-extension/src/entrypoints/content.tsindex 261621108..602399a8b 100644--- a/apps/browser-extension/src/entrypoints/content.ts+++ b/apps/browser-extension/src/entrypoints/content.ts@@ -63,18 +63,32 @@ export default defineContentScript({const { isValid, inputElement } = validateInputField(e.target as Element);if (isValid && inputElement) {+ /**+ * Immediately store the original autocomplete value and disable native autocomplete.+ * This must happen as early as possible to prevent native browser autofill from showing.+ */+ const originalAutocomplete = inputElement.getAttribute('autocomplete');+ if (originalAutocomplete && !inputElement.hasAttribute('data-av-autocomplete')) {+ inputElement.setAttribute('data-av-autocomplete', originalAutocomplete);+ }+ inputElement.setAttribute('autocomplete', 'off');+const formDetector = new FormDetector(document, inputElement);if (!formDetector.containsLoginForm()) {return;}// Only show popup for autofill-triggerable fields- if (!formDetector.isAutofillTriggerableField()) {+ const detectedFieldType = formDetector.getDetectedFieldType();+ if (!detectedFieldType) {return;}// Only inject icon and show popup if autofill popup is enabledif (await isAutoShowPopupEnabled()) {+ // Store our detected field type for subsequent clicks+ inputElement.setAttribute('data-av-field-type', detectedFieldType);+injectIcon(inputElement, container);// Only show popup if debounce time has passeddiff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex 0afa81621..2684e86a6 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -213,8 +213,6 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]const creatingText = await t('content.creatingNewAlias');const failedText = await t('content.failedToCreateIdentity');- // Disable browser's native autocomplete to avoid conflicts with AliasVault's autocomplete.- input.setAttribute('autocomplete', 'false');const popup = createBasePopup(input, rootContainer);// Create credential list container with IDdiff --git a/apps/browser-extension/src/utils/formDetector/FormDetector.ts b/apps/browser-extension/src/utils/formDetector/FormDetector.tsindex 01a972ac1..73f03d022 100644--- a/apps/browser-extension/src/utils/formDetector/FormDetector.ts+++ b/apps/browser-extension/src/utils/formDetector/FormDetector.ts@@ -360,8 +360,12 @@ export class FormDetector {continue;}- // Check autocomplete attribute for direct field type matching- const autocomplete = input.getAttribute('autocomplete')?.toLowerCase() ?? '';+ /**+ * Check autocomplete attribute for direct field type matching.+ * First check our custom data-av-autocomplete attribute (set by AliasVault when disabling+ * native browser autofill), then fall back to the regular autocomplete attribute.+ */+ const autocomplete = (input.getAttribute('data-av-autocomplete') ?? input.getAttribute('autocomplete'))?.toLowerCase() ?? '';// Direct autocomplete matches take highest priority (score -2, higher than type=email at -1)if (autocomplete) {@@ -902,16 +906,40 @@ export class FormDetector {* Check if a field is an autofill-triggerable field (username, email, or password).*/public isAutofillTriggerableField(): boolean {- // Check if it's a username, email or password field by reusing the existing detection logic- const formWrapper = this.getFormWrapper();+ return this.getDetectedFieldType() !== null;+ }+ /**+ * Get the detected field type for the clicked element.+ * Returns 'username', 'password', or 'email' if detected, null otherwise.+ * First checks for our custom data-av-field-type attribute (set on previous interactions),+ * then falls back to full field detection.+ */+ public getDetectedFieldType(): string | null {if (!this.clickedElement) {- return false;+ return null;+ }++ // First check if we already detected and stored the field type+ const storedFieldType = this.clickedElement.getAttribute('data-av-field-type');+ if (storedFieldType) {+ return storedFieldType;}// Get the actual input element (handles shadow DOM)const actualElement = this.getActualInputElement(this.clickedElement);+ // Also check the actual element for stored field type+ if (actualElement !== this.clickedElement) {+ const actualStoredFieldType = actualElement.getAttribute('data-av-field-type');+ if (actualStoredFieldType) {+ return actualStoredFieldType;+ }+ }++ // Fall back to full field detection+ const formWrapper = this.getFormWrapper();+// Check both the clicked element and the actual input elementconst elementsToCheck = [this.clickedElement, actualElement].filter((el, index, arr) =>el && arr.indexOf(el) === index // Remove duplicates@@ -920,23 +948,23 @@ export class FormDetector {// Check if any of the elements is a username fieldconst usernameFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.username, ['text']);if (usernameFields.some(input => elementsToCheck.includes(input))) {- return true;+ return 'username';}// Check if any of the elements is a password fieldconst passwordField = this.findPasswordField(formWrapper as HTMLFormElement | null);if ((passwordField.primary && elementsToCheck.includes(passwordField.primary)) ||(passwordField.confirm && elementsToCheck.includes(passwordField.confirm))) {- return true;+ return 'password';}// Check if any of the elements is an email fieldconst emailFields = this.findAllInputFields(formWrapper as HTMLFormElement | null, CombinedFieldPatterns.email, ['text', 'email']);if (emailFields.some(input => elementsToCheck.includes(input))) {- return true;+ return 'email';}- return false;+ return null;}/**