Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add explicit autofill trigger to context menu (#541)
Leendert de Borstbb9e986874f1
diff --git a/browser-extensions/chrome/contentScript.ts b/browser-extensions/chrome/contentScript.tsindex 10af194df..6b45a8cb5 100644--- a/browser-extensions/chrome/contentScript.ts+++ b/browser-extensions/chrome/contentScript.ts@@ -29,7 +29,26 @@ document.addEventListener('focusin', async (e) => {}});-// Also listen for popstate events (back/forward navigation)+/**+ * Listen for popstate events (back/forward navigation)+ */window.addEventListener('popstate', () => {removeExistingPopup();+});++/**+ * Listen for messages from the background script.+ */+window.addEventListener('message', (event) => {+ if (event.data.type === 'OPEN_ALIASVAULT_POPUP') {+ const elementIdentifier = event.data.elementIdentifier;+ if (elementIdentifier) {+ const target = document.getElementById(elementIdentifier) ||+ document.getElementsByName(elementIdentifier)[0];++ if (target instanceof HTMLInputElement) {+ openAutofillPopup(target, true); // Pass true to force open+ }+ }+ }});\ No newline at end of filediff --git a/browser-extensions/chrome/src/background/ContextMenu.ts b/browser-extensions/chrome/src/background/ContextMenu.tsindex 9c1cd041f..1fa55cb70 100644--- a/browser-extensions/chrome/src/background/ContextMenu.ts+++ b/browser-extensions/chrome/src/background/ContextMenu.ts@@ -4,16 +4,34 @@ import { PasswordGenerator } from '../shared/generators/Password/PasswordGenerat* Setup the context menus.*/export function setupContextMenus() : void {+ // Create root menuchrome.contextMenus.create({id: "aliasvault-root",title: "AliasVault",contexts: ["all"]});+ // Add fill option first (only for editable fields)+ chrome.contextMenus.create({+ id: "aliasvault-activate-form",+ parentId: "aliasvault-root",+ title: "Autofill with AliasVault",+ contexts: ["editable"],+ });++ // Add separator (only for editable fields)+ chrome.contextMenus.create({+ id: "aliasvault-separator",+ parentId: "aliasvault-root",+ type: "separator",+ contexts: ["editable"],+ });++ // Add password generator optionchrome.contextMenus.create({id: "aliasvault-generate-password",parentId: "aliasvault-root",- title: "Generate Password (copy to clipboard)",+ title: "Generate random password (copy to clipboard)",contexts: ["all"]});}@@ -36,6 +54,13 @@ export function handleContextMenuClick(info: chrome.contextMenus.OnClickData, ta});}}++ if (info.menuItemId === "aliasvault-activate-form" && tab?.id) {+ chrome.scripting.executeScript({+ target: { tabId: tab.id },+ func: activateAliasVaultForm,+ });+ }}/**@@ -66,4 +91,21 @@ function copyPasswordToClipboard(generatedPassword: string) : void {document.body.appendChild(notification);setTimeout(() => notification.remove(), 3000);}+}++/**+ * Activate AliasVault for the active input element.+ */+function activateAliasVaultForm() : void {+ const target = document.activeElement;+ if (target instanceof HTMLInputElement) {+ // Get the element's identifier (id or name)+ const elementIdentifier = target.id || target.name || '';+ if (elementIdentifier) {+ window.postMessage({+ type: 'OPEN_ALIASVAULT_POPUP',+ elementIdentifier+ }, '*');+ }+ }}\ No newline at end of filediff --git a/browser-extensions/chrome/src/contentScript/Popup.ts b/browser-extensions/chrome/src/contentScript/Popup.tsindex f926f0847..0b562d4a5 100644--- a/browser-extensions/chrome/src/contentScript/Popup.ts+++ b/browser-extensions/chrome/src/contentScript/Popup.ts@@ -1009,9 +1009,9 @@ export async function createEditNamePopup(defaultName: string): Promise<string |/*** Open (or refresh) the autofill popup including check if vault is locked.*/-export function openAutofillPopup(input: HTMLInputElement) : void {+export function openAutofillPopup(input: HTMLInputElement, forceOpen: boolean = false) : void {const formDetector = new FormDetector(document, input);- const forms = formDetector.detectForms();+ const forms = formDetector.detectForms(forceOpen);if (!forms.length) return;diff --git a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts b/browser-extensions/chrome/src/shared/formDetector/FormDetector.tsindex 7bb84d8de..c1267abba 100644--- a/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts+++ b/browser-extensions/chrome/src/shared/formDetector/FormDetector.ts@@ -19,13 +19,15 @@ export class FormDetector {/*** Detect login forms on the page based on the clicked element.+ *+ * @param force - Force the detection of forms, skipping checks such as if the element contains autocomplete="off".*/- public detectForms(): LoginForm[] {+ public detectForms(force: boolean = false): LoginForm[] {if (this.clickedElement) {const formWrapper = this.clickedElement.closest('form') ?? this.document.body;// Check if the wrapper contains a password or likely username field before processing.- if (this.containsPasswordField(formWrapper) || this.containsLikelyUsernameOrEmailField(formWrapper)) {+ if (this.containsPasswordField(formWrapper) || this.containsLikelyUsernameOrEmailField(formWrapper, force)) {this.createFormEntry(formWrapper);}}@@ -357,17 +359,23 @@ export class FormDetector {/*** Check if a form contains a likely username or email field.*/- private containsLikelyUsernameOrEmailField(wrapper: HTMLElement): boolean {+ private containsLikelyUsernameOrEmailField(wrapper: HTMLElement, force: boolean = false): boolean {// Check if the form contains an email field.const emailFields = this.findEmailField(wrapper as HTMLFormElement | null);- if (emailFields.primary && emailFields.primary.getAttribute('autocomplete') !== 'off') {- return true;+ if (emailFields.primary) {+ const isValid = force || emailFields.primary.getAttribute('autocomplete') !== 'off';+ if (isValid) {+ return true;+ }}// Check if the form contains a username field.const usernameField = this.findInputField(wrapper as HTMLFormElement | null, ['username', 'gebruikersnaam', 'gebruiker', 'login', 'identifier', 'user'], ['text'], []);- if (usernameField && usernameField.getAttribute('autocomplete') !== 'off') {- return true;+ if (usernameField) {+ const isValid = force || usernameField.getAttribute('autocomplete') !== 'off';+ if (isValid) {+ return true;+ }}return false;