Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add manual credential option to create new alias popup (#758)
Leendert de Borst81362b165b1e
diff --git a/browser-extension/src/entrypoints/contentScript/Popup.ts b/browser-extension/src/entrypoints/contentScript/Popup.tsindex 46373597a..e15f05650 100644--- a/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -188,9 +188,9 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Credene.stopImmediatePropagation();const suggestedName = getSuggestedServiceName(document, window.location);- const serviceName = await createEditNamePopup(suggestedName, rootContainer);+ const result = await createEditNamePopup(suggestedName, rootContainer);- if (!serviceName) {+ if (!result) {// User cancelledreturn;}@@ -205,71 +205,70 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Credenconst response = await sendMessage('GET_DEFAULT_EMAIL_DOMAIN', {}, 'background') as { domain: string };const domain = response.domain;- // Generate new identity locally- const identityGenerator = new IdentityGeneratorEn();- const identity = await identityGenerator.generateRandomIdentity();-- // Get password settings from background- const passwordSettingsResponse = await sendMessage('GET_PASSWORD_SETTINGS', {}, 'background') as PasswordSettingsResponse;-- // Initialize password generator with the retrieved settings- const passwordGenerator = new PasswordGenerator(passwordSettingsResponse.settings);- const password = passwordGenerator.generateRandomPassword();-- // Extract favicon from page and get the bytes- const faviconBytes = await getFaviconBytes(document);-- /**- * Get a valid service URL from the current page.- */- const getValidServiceUrl = (): string | null => {- try {- // Check if we're in an iframe with invalid/null source- if (window !== window.top && (!window.location.href || window.location.href === 'about:srcdoc')) {- return null;+ let credential: Credential;++ if (result.isCustomCredential) {+ // Create custom credential+ const faviconBytes = await getFaviconBytes(document);+ credential = {+ Id: '',+ ServiceName: result.serviceName || '',+ ServiceUrl: getValidServiceUrl(),+ Email: result.customEmail || '',+ Logo: faviconBytes || undefined,+ Username: result.customUsername || '',+ Password: '', // Will be set by the popup+ Notes: '',+ Alias: {+ FirstName: '',+ LastName: '',+ NickName: result.customUsername || '',+ BirthDate: new Date().toISOString(),+ Gender: undefined,+ Email: result.customEmail || ''}-- const url = new URL(window.location.href);-- // Validate the domain/origin- if (!url.origin || url.origin === 'null' || !url.hostname) {- return null;+ };+ } else {+ // Generate new identity locally+ const identityGenerator = new IdentityGeneratorEn();+ const identity = await identityGenerator.generateRandomIdentity();++ // Get password settings from background+ const passwordSettingsResponse = await sendMessage('GET_PASSWORD_SETTINGS', {}, 'background') as PasswordSettingsResponse;++ // Initialize password generator with the retrieved settings+ const passwordGenerator = new PasswordGenerator({+ Length: 16,+ UseUppercase: true,+ UseLowercase: true,+ UseNumbers: true,+ UseSpecialChars: true,+ UseNonAmbiguousChars: false+ });+ const password = passwordGenerator.generateRandomPassword();++ // Extract favicon from page and get the bytes+ const faviconBytes = await getFaviconBytes(document);++ credential = {+ Id: '',+ ServiceName: result.serviceName || '',+ ServiceUrl: getValidServiceUrl(),+ Email: `${identity.emailPrefix}@${domain}`,+ Logo: faviconBytes || undefined,+ Username: identity.nickName,+ Password: password,+ Notes: '',+ Alias: {+ FirstName: identity.firstName,+ LastName: identity.lastName,+ NickName: identity.nickName,+ BirthDate: identity.birthDate.toISOString(),+ Gender: identity.gender,+ Email: `${identity.emailPrefix}@${domain}`}-- // Check for valid protocol (only http/https)- if (!(/^https?:$/).exec(url.protocol)) {- return null;- }-- return url.origin + url.pathname;- } catch (error) {- console.debug('Error validating service URL:', error);- return null;- }- };-- // Get valid service URL, defaults to empty string if invalid- const serviceUrl = getValidServiceUrl() ?? '';-- // Submit new identity to backend to persist in db- const credential: Credential = {- Id: '',- ServiceName: serviceName,- ServiceUrl: serviceUrl,- Email: `${identity.emailPrefix}@${domain}`,- Logo: faviconBytes ? new Uint8Array(faviconBytes) : undefined,- Username: identity.nickName,- Password: password,- Notes: '',- Alias: {- FirstName: identity.firstName,- LastName: identity.lastName,- NickName: identity.nickName,- BirthDate: identity.birthDate.toISOString(),- Gender: identity.gender,- Email: `${identity.emailPrefix}@${domain}`- }- };+ };+ }// Create identity in background.await sendMessage('CREATE_IDENTITY', {@@ -348,6 +347,8 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: CredenactionContainer.appendChild(closeButton);popup.appendChild(actionContainer);+ console.log('Autofill actually popup appended:', popup);+/*** Handle clicking outside the popup.*/@@ -650,7 +651,7 @@ export async function disableAutoShowPopup(): Promise<void> {/*** Create edit name popup. Part of the "create new alias" flow.*/-export async function createEditNamePopup(defaultName: string, rootContainer: HTMLElement): Promise<string | null> {+export async function createEditNamePopup(defaultName: string, rootContainer: HTMLElement): Promise<{ serviceName: string | null, isCustomCredential: boolean, customEmail?: string, customUsername?: string } | null> {// Close existing popupremoveExistingPopup(rootContainer);@@ -663,20 +664,120 @@ export async function createEditNamePopup(defaultName: string, rootContainer: HTconst popup = document.createElement('div');popup.className = 'av-create-popup';+ // Create the main contentpopup.innerHTML = `- <h3 class="av-create-popup-title">- New alias name- </h3>- <input- type="text"- id="service-name-input"- data-aliasvault-ignore="true"- value="${defaultName}"- class="av-create-popup-input"- >- <div class="av-create-popup-actions">- <button id="cancel-btn" class="av-create-popup-cancel">Cancel</button>- <button id="save-btn" class="av-create-popup-save">Create alias</button>+ <button class="av-create-popup-close">+ <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>+ </button>+ <div class="av-create-popup-mode-select">+ <h3 class="av-create-popup-title">Create New Alias</h3>+ <div class="av-create-popup-modes">+ <button class="av-create-popup-mode-btn av-create-popup-mode-random">+ <div class="av-create-popup-mode-icon">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/>+ <path d="M12 6c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm0 10c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4z"/>+ </svg>+ </div>+ <div class="av-create-popup-mode-content">+ <h4>Random Alias</h4>+ <p>Generate a random identity with random email</p>+ </div>+ </button>+ <button class="av-create-popup-mode-btn av-create-popup-mode-custom">+ <div class="av-create-popup-mode-icon">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/>+ <path d="M12 6c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm0 10c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4z"/>+ </svg>+ </div>+ <div class="av-create-popup-mode-content">+ <h4>Manual Credential</h4>+ <p>Create a custom username and password</p>+ </div>+ </button>+ </div>+ </div>++ <div class="av-create-popup-random-mode" style="display: none;">+ <h3 class="av-create-popup-title">Create Random Alias</h3>+ <div class="av-create-popup-field-group">+ <label for="service-name-input">Service Name</label>+ <input+ type="text"+ id="service-name-input"+ data-aliasvault-ignore="true"+ value="${defaultName}"+ class="av-create-popup-input"+ placeholder="Enter service name"+ >+ </div>+ <div class="av-create-popup-actions">+ <button id="back-btn" class="av-create-popup-back">Back</button>+ <button id="cancel-btn" class="av-create-popup-cancel">Cancel</button>+ <button id="save-btn" class="av-create-popup-save">Create alias</button>+ </div>+ </div>++ <div class="av-create-popup-custom-mode" style="display: none;">+ <h3 class="av-create-popup-title">Create Manual Credential</h3>+ <div class="av-create-popup-field-group">+ <label for="custom-service-name">Service Name</label>+ <input+ type="text"+ id="custom-service-name"+ data-aliasvault-ignore="true"+ value="${defaultName}"+ class="av-create-popup-input"+ placeholder="Enter service name"+ >+ </div>+ <div class="av-create-popup-field-group">+ <label for="custom-email">Email</label>+ <input+ type="email"+ id="custom-email"+ data-aliasvault-ignore="true"+ class="av-create-popup-input"+ placeholder="Enter email address"+ >+ </div>+ <div class="av-create-popup-field-group">+ <label for="custom-username">Username</label>+ <input+ type="text"+ id="custom-username"+ data-aliasvault-ignore="true"+ class="av-create-popup-input"+ placeholder="Enter username"+ >+ </div>+ <div class="av-create-popup-field-group">+ <label>Generated Password</label>+ <div class="av-create-popup-password-preview">+ <input+ type="text"+ id="password-preview"+ data-aliasvault-ignore="true"+ class="av-create-popup-input"+ readonly+ >+ <button id="regenerate-password" class="av-create-popup-regenerate-btn">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path>+ <path d="M3 3v5h5"></path>+ </svg>+ </button>+ </div>+ </div>+ <div class="av-create-popup-actions">+ <button id="custom-back-btn" class="av-create-popup-back">Back</button>+ <button id="custom-cancel-btn" class="av-create-popup-cancel">Cancel</button>+ <button id="custom-save-btn" class="av-create-popup-save">Create credential</button>+ </div></div>`;@@ -688,17 +789,75 @@ export async function createEditNamePopup(defaultName: string, rootContainer: HTpopup.classList.add('show');});- const input = popup.querySelector('#service-name-input') as HTMLInputElement;- const saveBtn = popup.querySelector('#save-btn') as HTMLButtonElement;+ // Get all the elements+ const modeSelect = popup.querySelector('.av-create-popup-mode-select') as HTMLElement;+ const randomMode = popup.querySelector('.av-create-popup-random-mode') as HTMLElement;+ const customMode = popup.querySelector('.av-create-popup-custom-mode') as HTMLElement;+ const randomBtn = popup.querySelector('.av-create-popup-mode-random') as HTMLButtonElement;+ const customBtn = popup.querySelector('.av-create-popup-mode-custom') as HTMLButtonElement;+ const backBtn = popup.querySelector('#back-btn') as HTMLButtonElement;+ const customBackBtn = popup.querySelector('#custom-back-btn') as HTMLButtonElement;const cancelBtn = popup.querySelector('#cancel-btn') as HTMLButtonElement;+ const customCancelBtn = popup.querySelector('#custom-cancel-btn') as HTMLButtonElement;+ const saveBtn = popup.querySelector('#save-btn') as HTMLButtonElement;+ const customSaveBtn = popup.querySelector('#custom-save-btn') as HTMLButtonElement;+ const input = popup.querySelector('#service-name-input') as HTMLInputElement;+ const customInput = popup.querySelector('#custom-service-name') as HTMLInputElement;+ const customEmail = popup.querySelector('#custom-email') as HTMLInputElement;+ const customUsername = popup.querySelector('#custom-username') as HTMLInputElement;+ const passwordPreview = popup.querySelector('#password-preview') as HTMLInputElement;+ const regenerateBtn = popup.querySelector('#regenerate-password') as HTMLButtonElement;+ const closeBtn = popup.querySelector('.av-create-popup-close') as HTMLButtonElement;++ // Initialize password generator+ const passwordGenerator = new PasswordGenerator({+ Length: 16,+ UseUppercase: true,+ UseLowercase: true,+ UseNumbers: true,+ UseSpecialChars: true,+ UseNonAmbiguousChars: false+ });++ // Function to generate and set password+ const generatePassword = () => {+ passwordPreview.value = passwordGenerator.generateRandomPassword();+ };++ // Generate initial password+ generatePassword();++ // Handle regenerate button click+ regenerateBtn.addEventListener('click', generatePassword);++ // Handle mode selection+ randomBtn.addEventListener('click', () => {+ modeSelect.style.display = 'none';+ randomMode.style.display = 'block';+ input.select();+ });++ customBtn.addEventListener('click', () => {+ modeSelect.style.display = 'none';+ customMode.style.display = 'block';+ customInput.select();+ });++ // Handle back buttons+ backBtn.addEventListener('click', () => {+ randomMode.style.display = 'none';+ modeSelect.style.display = 'block';+ });- // Select input text- input.select();+ customBackBtn.addEventListener('click', () => {+ customMode.style.display = 'none';+ modeSelect.style.display = 'block';+ });/*** Close the popup.*/- const closePopup = (value: string | null) : void => {+ const closePopup = (value: { serviceName: string | null, isCustomCredential: boolean, customEmail?: string, customUsername?: string } | null) : void => {popup.classList.remove('show');setTimeout(() => {overlay.remove();@@ -706,43 +865,90 @@ export async function createEditNamePopup(defaultName: string, rootContainer: HT}, 200);};- // Handle save+ // Handle save buttonssaveBtn.addEventListener('click', () => {- const value = input.value.trim();- if (value) {- closePopup(value);+ const serviceName = input.value.trim();+ if (serviceName) {+ closePopup({+ serviceName,+ isCustomCredential: false+ });}});- // Handle cancel+ customSaveBtn.addEventListener('click', () => {+ const serviceName = customInput.value.trim();+ if (serviceName) {+ if (!customEmail.value.trim() && !customUsername.value.trim()) {+ // Show error message+ const errorMsg = document.createElement('div');+ errorMsg.className = 'av-create-popup-error';+ errorMsg.textContent = 'Please fill in either email or username';+ customMode.insertBefore(errorMsg, customMode.querySelector('.av-create-popup-actions'));+ setTimeout(() => errorMsg.remove(), 2000);+ return;+ }+ closePopup({+ serviceName,+ isCustomCredential: true,+ customEmail: customEmail.value.trim(),+ customUsername: customUsername.value.trim()+ });+ }+ });++ // Handle cancel buttonscancelBtn.addEventListener('click', () => {closePopup(null);});+ customCancelBtn.addEventListener('click', () => {+ closePopup(null);+ });+// Handle Enter keyinput.addEventListener('keyup', (e) => {if (e.key === 'Enter') {- const value = input.value.trim();- if (value) {- closePopup(value);+ const serviceName = input.value.trim();+ if (serviceName) {+ closePopup({+ serviceName,+ isCustomCredential: false+ });}}});+ customInput.addEventListener('keyup', (e) => {+ if (e.key === 'Enter') {+ const serviceName = customInput.value.trim();+ if (serviceName) {+ if (!customEmail.value.trim() && !customUsername.value.trim()) {+ return;+ }+ closePopup({+ serviceName,+ isCustomCredential: true,+ customEmail: customEmail.value.trim(),+ customUsername: customUsername.value.trim()+ });+ }+ }+ });++ // Handle close button+ closeBtn.addEventListener('click', () => {+ closePopup(null);+ });+// Handle click outsideoverlay.addEventListener('click', (e) => {if (e.target === overlay) {- // Check if there's any text selected in the input- const selectedText = input.value.substring(input.selectionStart ?? 0, input.selectionEnd ?? 0);-- // Only close if no text is selected- if (!selectedText) {- closePopup(null);- }+ closePopup(null);}});});-};+}/*** Open (or refresh) the autofill popup including check if vault is locked.@@ -765,6 +971,7 @@ export function openAutofillPopup(input: HTMLInputElement, container: HTMLElemenconst response = await sendMessage('GET_CREDENTIALS', { }, 'background') as CredentialsResponse;if (response.success) {+ console.log('creating autofill popup...');createAutofillPopup(input, response.credentials, container);} else {createVaultLockedPopup(input, container);@@ -943,3 +1150,32 @@ function getSuggestedServiceName(document: Document, location: Location): stringconst domainParts = location.hostname.replace(/^www\./, '').split('.');return domainParts.slice(-2).join('.');}++/**+ * Get a valid service URL from the current page.+ */+function getValidServiceUrl(): string {+ try {+ // Check if we're in an iframe with invalid/null source+ if (window !== window.top && (!window.location.href || window.location.href === 'about:srcdoc')) {+ return '';+ }++ const url = new URL(window.location.href);++ // Validate the domain/origin+ if (!url.origin || url.origin === 'null' || !url.hostname) {+ return '';+ }++ // Check for valid protocol (only http/https)+ if (!(/^https?:$/).exec(url.protocol)) {+ return '';+ }++ return url.origin + url.pathname;+ } catch (error) {+ console.debug('Error validating service URL:', error);+ return '';+ }+}diff --git a/browser-extension/src/entrypoints/contentScript/style.css b/browser-extension/src/entrypoints/contentScript/style.cssindex 5766fbb6c..0f3633113 100644--- a/browser-extension/src/entrypoints/contentScript/style.css+++ b/browser-extension/src/entrypoints/contentScript/style.css@@ -303,6 +303,7 @@ body {transform: scale(0.95);opacity: 0;padding: 24px;+ padding-top: 16px;transition: transform 0.2s ease, opacity 0.2s ease;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;}@@ -313,17 +314,106 @@ body {}.av-create-popup-title {- margin: 0 0 16px 0;- font-size: 18px;+ margin: 0 0 24px 0;+ font-size: 20px;font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;font-weight: 600;color: #f8f9fa;+ text-align: center;+}++.av-create-popup-close {+ position: absolute;+ right: 16px;+ top: 16px;+ padding: 6px;+ background: #374151;+ border: none;+ cursor: pointer;+ color: #9ca3af;+ border-radius: 4px;+ transition: all 0.2s ease;+ display: flex;+ align-items: center;+ justify-content: center;+ width: 28px;+ height: 28px;+ z-index: 1;+}++.av-create-popup-close:hover {+ color: #f8f9fa;+ background: #4b5563;+}++.av-create-popup-close .av-icon {+ width: 16px;+ height: 16px;+}++.av-create-popup-modes {+ display: flex;+ flex-direction: column;+ gap: 16px;+ margin-bottom: 10px;+}++.av-create-popup-mode-btn {+ display: flex;+ align-items: center;+ gap: 16px;+ padding: 8px;+ background: #374151;+ border: 1px solid #4b5563;+ border-radius: 8px;+ cursor: pointer;+ transition: all 0.2s ease;+ text-align: left;+ width: 100%;+}++.av-create-popup-mode-btn:hover {+ background: #4b5563;+ transform: translateY(-1px);+}++.av-create-popup-mode-icon {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 48px;+ height: 48px;+ background: #1f2937;+ border-radius: 8px;+ color: #d68338;+}++.av-create-popup-mode-icon .av-icon {+ width: 24px;+ height: 24px;+}++.av-create-popup-mode-content {+ flex: 1;+}++.av-create-popup-mode-content h4 {+ margin: 0 0 4px 0;+ font-size: 16px;+ font-weight: 600;+ color: #f8f9fa;+}++.av-create-popup-mode-content p {+ margin: 0;+ font-size: 14px;+ color: #9ca3af;}.av-create-popup-input {width: 100%;padding: 8px 12px;- margin-bottom: 24px;+ margin-bottom: 16px;border: 1px solid #374151;border-radius: 6px;background: #374151;@@ -338,10 +428,101 @@ body {box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);}+/* Custom Credential UI Styles */+.av-create-popup-custom-toggle {+ margin: 16px 0;+ padding: 0 16px;+}++.av-create-popup-toggle-label {+ display: flex;+ align-items: center;+ gap: 8px;+ cursor: pointer;+ user-select: none;+}++.av-create-popup-toggle-text {+ font-size: 14px;+ color: #4b5563;+}++.av-create-popup-custom-fields {+ margin: 16px 0;+ padding: 0 16px;+}++.av-create-popup-field-group {+ margin-bottom: 2px;+}++.av-create-popup-field-group label {+ display: block;+ margin-bottom: 8px;+ font-size: 14px;+ color: #eee;+}++.av-create-popup-password-preview {+ display: flex;+ gap: 8px;+ align-items: center;+}++.av-create-popup-password-preview input {+ flex: 1;+}++.av-create-popup-regenerate-btn {+ padding: 8px;+ border: none;+ background: #374151;+ cursor: pointer;+ color: #9ca3af;+ border-radius: 4px;+ transition: all 0.2s ease;+}++.av-create-popup-regenerate-btn:hover {+ background: #4b5563;+ color: #f8f9fa;+}++.av-create-popup-regenerate-btn .av-icon {+ width: 16px;+ height: 16px;+}++.av-create-popup-error {+ margin-top: 16px;+ padding: 8px 12px;+ background-color: #fee2e2;+ color: #dc2626;+ border-radius: 4px;+ font-size: 14px;+ animation: fadeIn 0.2s ease-in-out;+}+.av-create-popup-actions {display: flex;justify-content: flex-end;gap: 12px;+ margin-top: 24px;+}++.av-create-popup-back {+ padding: 8px 16px;+ border-radius: 6px;+ border: 1px solid #374151;+ background: transparent;+ color: #f8f9fa;+ cursor: pointer;+ font-size: 14px;+ transition: all 0.2s ease;+}++.av-create-popup-back:hover {+ background: #374151;}.av-create-popup-cancel {@@ -418,6 +599,17 @@ body {transition: opacity 0.2s ease-in-out;}+@keyframes fadeIn {+ from {+ opacity: 0;+ transform: translateY(-4px);+ }+ to {+ opacity: 1;+ transform: translateY(0);+ }+}+@keyframes fadeOut {0% { opacity: 1; transform: scale(1.02); }100% { opacity: 0; transform: scale(1); }