Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add dismiss for 1 hour option, add context menu disable option (#834)
Leendert de Borstfa3f4e78cc9d
diff --git a/apps/browser-extension/src/entrypoints/content.ts b/apps/browser-extension/src/entrypoints/content.tsindex db6088807..c54faa7b4 100644--- a/apps/browser-extension/src/entrypoints/content.ts+++ b/apps/browser-extension/src/entrypoints/content.ts@@ -1,9 +1,9 @@-import './contentScript/style.css';-import { FormDetector } from '../utils/formDetector/FormDetector';-import { isAutoShowPopupEnabled, openAutofillPopup, removeExistingPopup } from './contentScript/Popup';-import { injectIcon, popupDebounceTimeHasPassed, validateInputField } from './contentScript/Form';+import '@/entrypoints/contentScript/style.css';+import { FormDetector } from '@/utils/formDetector/FormDetector';+import { isAutoShowPopupEnabled, openAutofillPopup, removeExistingPopup } from '@/entrypoints/contentScript/Popup';+import { injectIcon, popupDebounceTimeHasPassed, validateInputField } from '@/entrypoints/contentScript/Form';import { onMessage } from "webext-bridge/content-script";-import { BoolResponse as messageBoolResponse } from '../utils/types/messaging/BoolResponse';+import { BoolResponse as messageBoolResponse } from '@/utils/types/messaging/BoolResponse';import { defineContentScript } from '#imports';import { createShadowRootUi } from '#imports';@@ -54,11 +54,14 @@ export default defineContentScript({return;}- injectIcon(inputElement, container);+ // Only inject icon and show popup if autofill popup is enabled+ if (await isAutoShowPopupEnabled()) {+ injectIcon(inputElement, container);- // Only show popup if its enabled and debounce time has passed.- if (await isAutoShowPopupEnabled() && popupDebounceTimeHasPassed()) {- openAutofillPopup(inputElement, container);+ // Only show popup if debounce time has passed+ if (popupDebounceTimeHasPassed()) {+ openAutofillPopup(inputElement, container);+ }}}};@@ -96,6 +99,7 @@ export default defineContentScript({return { success: false, error: 'No form found' };}+ // This is an explicit call by the user to open the popup, so we don't check if it's enabled.injectIcon(inputElement, container);openAutofillPopup(inputElement, container);return { success: true };diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex 680cff39c..099a857d2 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -14,8 +14,10 @@ import { Credential } from '@/utils/types/Credential';// TODO: store generic setting constants somewhere else.export const DISABLED_SITES_KEY = 'local:aliasvault_disabled_sites';-export const GLOBAL_POPUP_ENABLED_KEY = 'local:aliasvault_global_popup_enabled';+export const GLOBAL_AUTOFILL_POPUP_ENABLED_KEY = 'local:aliasvault_global_autofill_popup_enabled';+export const GLOBAL_CONTEXT_MENU_ENABLED_KEY = 'local:aliasvault_global_context_menu_enabled';export const VAULT_LOCKED_DISMISS_UNTIL_KEY = 'local:aliasvault_vault_locked_dismiss_until';+export const TEMPORARY_DISABLED_SITES_KEY = 'local:aliasvault_temporary_disabled_sites';// TODO: store these settings in the actual vault when updating the datamodel for roadmap v1.0.export const LAST_CUSTOM_EMAIL_KEY = 'local:aliasvault_last_custom_email';@@ -332,23 +334,77 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Credenconst closeButton = document.createElement('button');closeButton.className = 'av-button av-button-close';closeButton.innerHTML = `- <svg class="av-icon" viewBox="0 0 24 24">- <line x1="18" y1="6" x2="6" y2="18"></line>- <line x1="6" y1="6" x2="18" y2="18"></line>- </svg>-`;+ <svg class="av-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">+ <path d="M6 18L18 6M6 6l12 12" stroke-linecap="round" stroke-linejoin="round"/>+ </svg>+ `;/*** Handle close button click*/- const handleCloseClick = async (e: Event) : Promise<void> => {- e.preventDefault();+ const handleCloseClick = (e: Event): void => {e.stopPropagation();- e.stopImmediatePropagation();- await disableAutoShowPopup();- removeExistingPopup(rootContainer);+ const rect = closeButton.getBoundingClientRect();+ const contextMenu = document.createElement('div');+ contextMenu.className = 'av-context-menu';+ contextMenu.style.position = 'fixed';+ contextMenu.style.left = `${rect.left}px`;+ contextMenu.style.top = `${rect.bottom + 4}px`;+ contextMenu.innerHTML = `+ <button class="av-context-menu-item" data-action="temporary">+ <svg class="av-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">+ <path d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" stroke-linecap="round" stroke-linejoin="round"/>+ </svg>+ Dismiss for 1 hour (current site)+ </button>+ <button class="av-context-menu-item" data-action="permanent">+ <svg class="av-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">+ <path d="M6 18L18 6M6 6l12 12" stroke-linecap="round" stroke-linejoin="round"/>+ </svg>+ Dismiss permanently (current site)+ </button>+ `;++ // Remove any existing context menu+ const existingMenu = document.querySelector('.av-context-menu');+ if (existingMenu) {+ existingMenu.remove();+ }++ // Add the new context menu+ popup.appendChild(contextMenu);++ /**+ * Handle clicks on context menu items+ * @param e - The click event+ */+ const handleContextMenuClick = (e: MouseEvent): void => {+ const target = e.target as HTMLElement;+ const menuItem = target.closest('.av-context-menu-item') as HTMLElement;+ if (!menuItem) {+ // Clicked outside the menu, close everything+ contextMenu.remove();+ removeExistingPopup(rootContainer);+ document.removeEventListener('click', handleContextMenuClick);+ return;+ }++ const action = menuItem.dataset.action;+ if (action === 'temporary') {+ disableAutoShowPopup(true);+ } else if (action === 'permanent') {+ disableAutoShowPopup(false);+ }+ contextMenu.remove();+ removeExistingPopup(rootContainer);+ document.removeEventListener('click', handleContextMenuClick);+ };++ // Add click listener to handle menu item clicks+ contextMenu.addEventListener('click', handleContextMenuClick);};+ // Add click handlersaddReliableClickHandler(closeButton, handleCloseClick);actionContainer.appendChild(searchInput);@@ -621,7 +677,8 @@ function createCredentialList(credentials: Credential[], input: HTMLInputElement*/export async function isAutoShowPopupEnabled(): Promise<boolean> {const disabledSites = await storage.getItem(DISABLED_SITES_KEY) as string[] ?? [];- const globalPopupEnabled = await storage.getItem(GLOBAL_POPUP_ENABLED_KEY) ?? true;+ const temporaryDisabledSites = await storage.getItem(TEMPORARY_DISABLED_SITES_KEY) as Record<string, number> ?? {};+ const globalPopupEnabled = await storage.getItem(GLOBAL_AUTOFILL_POPUP_ENABLED_KEY) ?? true;const currentHostname = window.location.hostname;@@ -631,7 +688,14 @@ export async function isAutoShowPopupEnabled(): Promise<boolean> {}if (disabledSites.includes(currentHostname)) {- // Popup is disabled for current site.+ // Popup is permanently disabled for current site.+ return false;+ }++ // Check temporary disable+ const temporaryDisabledUntil = temporaryDisabledSites[currentHostname];+ if (temporaryDisabledUntil && Date.now() < temporaryDisabledUntil) {+ // Popup is temporarily disabled for current site.return false;}@@ -648,11 +712,21 @@ export async function isAutoShowPopupEnabled(): Promise<boolean> {/*** Disable auto-popup for current site*/-export async function disableAutoShowPopup(): Promise<void> {- const disabledSites = await storage.getItem(DISABLED_SITES_KEY) as string[] ?? [];- if (!disabledSites.includes(window.location.hostname)) {- disabledSites.push(window.location.hostname);- await storage.setItem(DISABLED_SITES_KEY, disabledSites);+export async function disableAutoShowPopup(temporary: boolean = false): Promise<void> {+ const currentHostname = window.location.hostname;++ if (temporary) {+ // Add to temporary disabled sites with 1 hour expiry+ const temporaryDisabledSites = await storage.getItem(TEMPORARY_DISABLED_SITES_KEY) as Record<string, number> ?? {};+ temporaryDisabledSites[currentHostname] = Date.now() + (60 * 60 * 1000); // 1 hour from now+ await storage.setItem(TEMPORARY_DISABLED_SITES_KEY, temporaryDisabledSites);+ } else {+ // Add to permanently disabled sites+ const disabledSites = await storage.getItem(DISABLED_SITES_KEY) as string[] ?? [];+ if (!disabledSites.includes(currentHostname)) {+ disabledSites.push(currentHostname);+ await storage.setItem(DISABLED_SITES_KEY, disabledSites);+ }}}diff --git a/apps/browser-extension/src/entrypoints/contentScript/style.css b/apps/browser-extension/src/entrypoints/contentScript/style.cssindex 0250d6d75..b55d4c573 100644--- a/apps/browser-extension/src/entrypoints/contentScript/style.css+++ b/apps/browser-extension/src/entrypoints/contentScript/style.css@@ -787,4 +787,47 @@ body {margin: 4px 0 0;font-size: 12px;color: #9ca3af;+}++/* Context Menu */+.av-context-menu {+ position: fixed;+ background: #1f2937;+ border: 1px solid #374151;+ border-radius: 6px;+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),+ 0 2px 4px -1px rgba(0, 0, 0, 0.06);+ z-index: 2147483647;+ min-width: 180px;+ padding: 4px;+ margin-top: 4px;+}++.av-context-menu-item {+ display: flex;+ align-items: center;+ gap: 8px;+ width: 100%;+ padding: 8px 12px;+ border: none;+ background: none;+ color: #e5e7eb;+ font-size: 14px;+ text-align: left;+ cursor: pointer;+ border-radius: 4px;+ transition: background-color 0.2s;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;+}++.av-context-menu-item:hover {+ background-color: #374151;+}++.av-context-menu-item .av-icon {+ width: 16px;+ height: 16px;+ stroke-width: 2;+ stroke-linecap: round;+ stroke-linejoin: round;}\ No newline at end of filediff --git a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsxindex 651addc94..790910554 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx@@ -1,7 +1,7 @@import React, { useState, useEffect } from 'react';import { AppInfo } from '@/utils/AppInfo';import { storage } from '#imports';-import { GLOBAL_POPUP_ENABLED_KEY, DISABLED_SITES_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY } from '@/entrypoints/contentScript/Popup';+import { GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, DISABLED_SITES_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY } from '@/entrypoints/contentScript/Popup';type ApiOption = {label: string;@@ -29,7 +29,7 @@ const AuthSettings: React.FC = () => {const loadStoredSettings = async () : Promise<void> => {const apiUrl = await storage.getItem('local:apiUrl') as string;const clientUrl = await storage.getItem('local:clientUrl') as string;- const globallyEnabled = await storage.getItem(GLOBAL_POPUP_ENABLED_KEY) !== false; // Default to true if not set+ const globallyEnabled = await storage.getItem(GLOBAL_AUTOFILL_POPUP_ENABLED_KEY) !== false; // Default to true if not setconst dismissUntil = await storage.getItem(VAULT_LOCKED_DISMISS_UNTIL_KEY) as number;if (dismissUntil) {@@ -91,7 +91,7 @@ const AuthSettings: React.FC = () => {const toggleGlobalPopup = async () : Promise<void> => {const newGloballyEnabled = !isGloballyEnabled;- await storage.setItem(GLOBAL_POPUP_ENABLED_KEY, newGloballyEnabled);+ await storage.setItem(GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, newGloballyEnabled);if (newGloballyEnabled) {// Reset all disabled sites when enabling globallydiff --git a/apps/browser-extension/src/entrypoints/popup/pages/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/Settings.tsxindex 9f8e9be56..f1218145b 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/Settings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/Settings.tsx@@ -1,18 +1,21 @@import React, { useEffect, useState, useCallback } from 'react';import { storage } from "#imports";-import { browser } from 'wxt/browser';-import { DISABLED_SITES_KEY, GLOBAL_POPUP_ENABLED_KEY } from '@/entrypoints/contentScript/Popup';+import { sendMessage } from 'webext-bridge/popup';+import { DISABLED_SITES_KEY, GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, GLOBAL_CONTEXT_MENU_ENABLED_KEY, TEMPORARY_DISABLED_SITES_KEY } from '@/entrypoints/contentScript/Popup';import { AppInfo } from '@/utils/AppInfo';import { useTheme } from '@/entrypoints/popup/context/ThemeContext';+import { browser } from 'wxt/browser';/*** Popup settings type.*/type PopupSettings = {disabledUrls: string[];+ temporaryDisabledUrls: Record<string, number>;currentUrl: string;isEnabled: boolean;isGloballyEnabled: boolean;+ isContextMenuEnabled: boolean;}/**@@ -22,15 +25,17 @@ const Settings: React.FC = () => {const { theme, setTheme } = useTheme();const [settings, setSettings] = useState<PopupSettings>({disabledUrls: [],+ temporaryDisabledUrls: {},currentUrl: '',isEnabled: true,- isGloballyEnabled: true+ isGloballyEnabled: true,+ isContextMenuEnabled: true});/*** Get current tab in browser.*/- const getCurrentTab = async (): Promise<browser.tabs.Tab> => {+ const getCurrentTab = async (): Promise<browser.Tabs.Tab> => {const queryOptions = { active: true, currentWindow: true };const [tab] = await browser.tabs.query(queryOptions);return tab;@@ -45,13 +50,27 @@ const Settings: React.FC = () => {// Load settings local storage.const disabledUrls = await storage.getItem(DISABLED_SITES_KEY) as string[] ?? [];- const isGloballyEnabled = await storage.getItem(GLOBAL_POPUP_ENABLED_KEY) !== false; // Default to true if not set+ const temporaryDisabledUrls = await storage.getItem(TEMPORARY_DISABLED_SITES_KEY) as Record<string, number> ?? {};+ const isGloballyEnabled = await storage.getItem(GLOBAL_AUTOFILL_POPUP_ENABLED_KEY) !== false; // Default to true if not set+ const isContextMenuEnabled = await storage.getItem(GLOBAL_CONTEXT_MENU_ENABLED_KEY) !== false; // Default to true if not set++ // Clean up expired temporary disables+ const now = Date.now();+ const cleanedTemporaryDisabledUrls = Object.fromEntries(+ Object.entries(temporaryDisabledUrls).filter(([_, expiry]) => expiry > now)+ );++ if (Object.keys(cleanedTemporaryDisabledUrls).length !== Object.keys(temporaryDisabledUrls).length) {+ await storage.setItem(TEMPORARY_DISABLED_SITES_KEY, cleanedTemporaryDisabledUrls);+ }setSettings({disabledUrls,+ temporaryDisabledUrls: cleanedTemporaryDisabledUrls,currentUrl,- isEnabled: !disabledUrls.includes(currentUrl),+ isEnabled: !disabledUrls.includes(currentUrl) && !(currentUrl in cleanedTemporaryDisabledUrls),isGloballyEnabled,+ isContextMenuEnabled});}, []);@@ -63,20 +82,31 @@ const Settings: React.FC = () => {* Toggle current site.*/const toggleCurrentSite = async () : Promise<void> => {- const { currentUrl, disabledUrls, isEnabled } = settings;+ const { currentUrl, disabledUrls, temporaryDisabledUrls, isEnabled } = settings;+let newDisabledUrls = [...disabledUrls];+ let newTemporaryDisabledUrls = { ...temporaryDisabledUrls };if (isEnabled) {- newDisabledUrls.push(currentUrl);+ // When disabling, add to permanent disabled list+ if (!newDisabledUrls.includes(currentUrl)) {+ newDisabledUrls.push(currentUrl);+ }+ // Also remove from temporary disabled list if present+ delete newTemporaryDisabledUrls[currentUrl];} else {+ // When enabling, remove from both permanent and temporary disabled listsnewDisabledUrls = newDisabledUrls.filter(url => url !== currentUrl);+ delete newTemporaryDisabledUrls[currentUrl];}await storage.setItem(DISABLED_SITES_KEY, newDisabledUrls);+ await storage.setItem(TEMPORARY_DISABLED_SITES_KEY, newTemporaryDisabledUrls);setSettings(prev => ({...prev,disabledUrls: newDisabledUrls,+ temporaryDisabledUrls: newTemporaryDisabledUrls,isEnabled: !isEnabled}));};@@ -86,10 +116,12 @@ const Settings: React.FC = () => {*/const resetSettings = async () : Promise<void> => {await storage.setItem(DISABLED_SITES_KEY, []);+ await storage.setItem(TEMPORARY_DISABLED_SITES_KEY, {});setSettings(prev => ({...prev,disabledUrls: [],+ temporaryDisabledUrls: {},isEnabled: true}));};@@ -100,7 +132,7 @@ const Settings: React.FC = () => {const toggleGlobalPopup = async () : Promise<void> => {const newGloballyEnabled = !settings.isGloballyEnabled;- await storage.setItem(GLOBAL_POPUP_ENABLED_KEY, newGloballyEnabled);+ await storage.setItem(GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, newGloballyEnabled);setSettings(prev => ({...prev,@@ -108,6 +140,21 @@ const Settings: React.FC = () => {}));};+ /**+ * Toggle context menu.+ */+ const toggleContextMenu = async () : Promise<void> => {+ const newContextMenuEnabled = !settings.isContextMenuEnabled;++ await storage.setItem(GLOBAL_CONTEXT_MENU_ENABLED_KEY, newContextMenuEnabled);+ await sendMessage('TOGGLE_CONTEXT_MENU', { enabled: newContextMenuEnabled }, 'background');++ setSettings(prev => ({+ ...prev,+ isContextMenuEnabled: newContextMenuEnabled+ }));+ };+/*** Set theme preference.*/@@ -132,10 +179,10 @@ const Settings: React.FC = () => {<section><h3 className="text-md font-semibold text-gray-900 dark:text-white mb-3">Global Settings</h3><div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">- <div className="p-4">+ <div className="p-4 space-y-4"><div className="flex items-center justify-between"><div>- <p className="text-sm font-medium text-gray-900 dark:text-white">Automatically open popup</p>+ <p className="text-sm font-medium text-gray-900 dark:text-white">Autofill popup</p><p className={`text-sm mt-1 ${settings.isGloballyEnabled ? 'text-gray-600 dark:text-gray-400' : 'text-red-600 dark:text-red-400'}`}>{settings.isGloballyEnabled ? 'Active on all sites (unless disabled below)' : 'Disabled on all sites'}</p>@@ -151,6 +198,25 @@ const Settings: React.FC = () => {{settings.isGloballyEnabled ? 'Enabled' : 'Disabled'}</button></div>++ <div className="flex items-center justify-between">+ <div>+ <p className="text-sm font-medium text-gray-900 dark:text-white">Right-click context menu</p>+ <p className={`text-sm mt-1 ${settings.isContextMenuEnabled ? 'text-gray-600 dark:text-gray-400' : 'text-red-600 dark:text-red-400'}`}>+ {settings.isContextMenuEnabled ? 'Enabled' : 'Disabled'}+ </p>+ </div>+ <button+ onClick={toggleContextMenu}+ className={`px-4 py-2 rounded-md transition-colors ${+ settings.isContextMenuEnabled+ ? 'bg-green-500 hover:bg-green-600 text-white'+ : 'bg-red-500 hover:bg-red-600 text-white'+ }`}+ >+ {settings.isContextMenuEnabled ? 'Enabled' : 'Disabled'}+ </button>+ </div></div></div></section>@@ -162,10 +228,15 @@ const Settings: React.FC = () => {<div className="p-4"><div className="flex items-center justify-between"><div>- <p className="text-sm font-medium text-gray-900 dark:text-white">Open popup on: {settings.currentUrl}</p>+ <p className="text-sm font-medium text-gray-900 dark:text-white">Autofill popup on: {settings.currentUrl}</p><p className={`text-sm mt-1 ${settings.isEnabled ? 'text-gray-600 dark:text-gray-400' : 'text-red-600 dark:text-red-400'}`}>{settings.isEnabled ? 'Enabled for this site' : 'Disabled for this site'}</p>+ {!settings.isEnabled && settings.temporaryDisabledUrls[settings.currentUrl] && (+ <p className="text-xs text-gray-500 dark:text-gray-400 mt-1">+ Temporarily disabled until {new Date(settings.temporaryDisabledUrls[settings.currentUrl]).toLocaleTimeString()}+ </p>+ )}</div><buttononClick={toggleCurrentSite}