Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Show service name suggestions (#798)

Leendert de Borste4f3de927ff9
diff --git a/browser-extension/src/entrypoints/contentScript/Popup.ts b/browser-extension/src/entrypoints/contentScript/Popup.ts
index f967162c3..751cfbb5e 100644
--- a/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -11,6 +11,7 @@ import SqliteClient from '../../utils/SqliteClient';
import { BaseIdentityGenerator } from '@/utils/generators/Identity/implementations/base/BaseIdentityGenerator';
import { StringResponse } from '@/utils/types/messaging/StringResponse';
import { FormDetector } from '@/utils/formDetector/FormDetector';
+import { Credential } from '@/utils/types/Credential';
// TODO: store generic setting constants somewhere else.
export const DISABLED_SITES_KEY = 'local:aliasvault_disabled_sites';
@@ -211,8 +212,8 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Creden
e.stopPropagation();
e.stopImmediatePropagation();
- const suggestedName = FormDetector.getSuggestedServiceName(document, window.location);
- const result = await createAliasCreationPopup(suggestedName, rootContainer);
+ const suggestedNames = FormDetector.getSuggestedServiceName(document, window.location);
+ const result = await createAliasCreationPopup(suggestedNames, rootContainer);
if (!result) {
// User cancelled
@@ -671,7 +672,7 @@ export async function disableAutoShowPopup(): Promise<void> {
/**
* Create alias creation popup where user can choose between random alias and custom alias.
*/
-export async function createAliasCreationPopup(defaultName: string, rootContainer: HTMLElement): Promise<{ serviceName: string | null, isCustomCredential: boolean, customEmail?: string, customUsername?: string, customPassword?: string } | null> {
+export async function createAliasCreationPopup(suggestedNames: string[], rootContainer: HTMLElement): Promise<{ serviceName: string | null, isCustomCredential: boolean, customEmail?: string, customUsername?: string, customPassword?: string } | null> {
// Close existing popup
removeExistingPopup(rootContainer);
@@ -761,10 +762,15 @@ export async function createAliasCreationPopup(defaultName: string, rootContaine
<input
type="text"
id="service-name-input"
- value="${defaultName}"
+ value="${suggestedNames[0] ?? ''}"
class="av-create-popup-input"
placeholder="Enter service name"
>
+ ${suggestedNames.length > 1 ? `
+ <div class="av-suggested-names">
+ ${getSuggestedNamesHtml(suggestedNames, suggestedNames[0] ?? '')}
+ </div>
+ ` : ''}
</div>
<div class="av-create-popup-actions">
<button id="cancel-btn" class="av-create-popup-cancel">Cancel</button>
@@ -778,10 +784,15 @@ export async function createAliasCreationPopup(defaultName: string, rootContaine
<input
type="text"
id="custom-service-name"
- value="${defaultName}"
+ value="${suggestedNames[0] ?? ''}"
class="av-create-popup-input"
placeholder="Enter service name"
>
+ ${suggestedNames.length > 1 ? `
+ <div class="av-suggested-names">
+ ${getSuggestedNamesHtml(suggestedNames, suggestedNames[0] ?? '')}
+ </div>
+ ` : ''}
</div>
<div class="av-create-popup-field-group">
<label for="custom-email">Email</label>
@@ -1169,11 +1180,52 @@ export async function createAliasCreationPopup(defaultName: string, rootContaine
// Use mousedown instead of click to prevent closing when dragging text
overlay.addEventListener('mousedown', handleClickOutside);
+ // Add event listeners for suggested names
+ const handleSuggestedNameClick = (e: Event) => {
+ const target = e.target as HTMLElement;
+ if (target.classList.contains('av-suggested-name')) {
+ const name = target.dataset.name;
+ if (name) {
+ // Get current input value
+ const currentValue = input.value;
+
+ // Update input with clicked name
+ input.value = name;
+ customInput.value = name;
+
+ // Update the suggested names section
+ const suggestedNamesContainer = target.closest('.av-suggested-names');
+ if (suggestedNamesContainer) {
+ // Update the suggestions HTML using the helper function
+ suggestedNamesContainer.innerHTML = getSuggestedNamesHtml(suggestedNames, name);
+ }
+ }
+ }
+ };
+
+ popup.addEventListener('click', handleSuggestedNameClick);
+
// Focus the input field
input.select();
});
}
+/**
+ * Get suggested names HTML with current input value excluded
+ */
+function getSuggestedNamesHtml(suggestedNames: string[], currentValue: string): string {
+ // Filter out the current value and create unique set of remaining suggestions
+ const filteredSuggestions = [...new Set(suggestedNames.filter(n => n !== currentValue))];
+
+ if (filteredSuggestions.length === 0) {
+ return '';
+ }
+
+ return `or ${filteredSuggestions.map((name, index) =>
+ `<span class="av-suggested-name" data-name="${name}">${name}</span>${index < filteredSuggestions.length - 1 ? ', ' : ''}`
+ ).join('')}?`;
+}
+
/**
* Get favicon bytes from page and resize if necessary.
*/
diff --git a/browser-extension/src/entrypoints/contentScript/style.css b/browser-extension/src/entrypoints/contentScript/style.css
index dd36c120c..d324e9524 100644
--- a/browser-extension/src/entrypoints/contentScript/style.css
+++ b/browser-extension/src/entrypoints/contentScript/style.css
@@ -113,6 +113,20 @@ body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
+.av-suggested-names {
+ margin-top: 4px;
+ font-size: 12px;
+ color: #acacac;
+}
+.av-suggested-name {
+ color: #bababa;
+ cursor: pointer;
+ text-decoration: underline;
+}
+.av-suggested-name:hover {
+ color: #d68338;
+}
+
.av-service-details {
font-size: 0.85em;
white-space: nowrap;
diff --git a/browser-extension/src/utils/formDetector/FieldPatterns.ts b/browser-extension/src/utils/formDetector/FieldPatterns.ts
index 20644ee36..8c309b4ea 100644
--- a/browser-extension/src/utils/formDetector/FieldPatterns.ts
+++ b/browser-extension/src/utils/formDetector/FieldPatterns.ts
@@ -180,7 +180,7 @@ export const DutchStopWords = new Set([
'vandaag', 'nu', 'huidig', 'recent', 'nieuwste',
// General
- 'je', 'in', 'op', 'de'
+ 'je', 'in', 'op', 'de', 'van', 'ons', 'allemaal'
]);
/**
diff --git a/browser-extension/src/utils/formDetector/FormDetector.ts b/browser-extension/src/utils/formDetector/FormDetector.ts
index 4fc3c4ff6..6dc367aff 100644
--- a/browser-extension/src/utils/formDetector/FormDetector.ts
+++ b/browser-extension/src/utils/formDetector/FormDetector.ts
@@ -54,10 +54,10 @@ export class FormDetector {
}
/**
- * Get a suggested service name from the page title and URL.
- * Attempts to extract meaningful parts while maintaining original capitalization.
+ * Get suggested service names from the page title and URL.
+ * Returns an array with two suggestions: the primary name and the domain name as an alternative.
*/
- public static getSuggestedServiceName(document: Document, location: Location): string {
+ public static getSuggestedServiceName(document: Document, location: Location): string[] {
const title = document.title;
const maxWords = 4;
const maxLength = 50;
@@ -105,6 +105,9 @@ export class FormDetector {
.join(' ');
};
+ // Domain name suggestion (always included as fallback or first suggestion)
+ const domainSuggestion = location.hostname.replace(/^www\./, '');
+
// First try to extract meaningful parts based on the divider
const dividerRegex = /[|\-—/\\:]/;
const dividerMatch = dividerRegex.exec(title);
@@ -117,13 +120,25 @@ export class FormDetector {
const beforeWords = getMeaningfulTitleParts(beforeDivider);
const afterWords = getMeaningfulTitleParts(afterDivider);
- // Choose the part with fewer meaningful words
- const chosenPart = beforeWords.length <= afterWords.length ? beforeDivider : afterDivider;
- const meaningfulParts = getMeaningfulTitleParts(chosenPart);
+ // Get both parts in original case
+ const beforePart = getOriginalCase(beforeDivider, beforeWords);
+ const afterPart = getOriginalCase(afterDivider, afterWords);
+
+ // Check if both parts are valid
+ const beforeValid = validLength(beforePart);
+ const afterValid = validLength(afterPart);
- const serviceName = getOriginalCase(chosenPart, meaningfulParts);
- if (validLength(serviceName)) {
- return serviceName;
+ // If both parts are valid, return both as suggestions
+ if (beforeValid && afterValid) {
+ return [beforePart, afterPart, domainSuggestion];
+ }
+
+ // If only one part is valid, return it
+ if (beforeValid) {
+ return [beforePart, domainSuggestion];
+ }
+ if (afterValid) {
+ return [afterPart, domainSuggestion];
}
}
@@ -131,12 +146,11 @@ export class FormDetector {
const meaningfulParts = getMeaningfulTitleParts(title);
const serviceName = getOriginalCase(title, meaningfulParts);
if (validLength(serviceName)) {
- return serviceName;
+ return [serviceName, domainSuggestion];
}
- // Fall back to domain name if no meaningful parts found
- const domainParts = location.hostname.replace(/^www\./, '').split('.');
- return domainParts.slice(-2).join('.');
+ // Fall back to domain name
+ return [domainSuggestion];
}
/**
diff --git a/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.en.test.ts b/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.en.test.ts
index 5b553eabf..d0af9fd0c 100644
--- a/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.en.test.ts
+++ b/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.en.test.ts
@@ -3,75 +3,75 @@ import { createTestDocument } from './TestUtils';
import { FormDetector } from '../FormDetector';
describe('FormDetector.getSuggestedServiceName (English)', () => {
- it('should extract service name from title with divider', () => {
+ it('should extract service name from title with divider and include domain', () => {
const { document, location } = createTestDocument(
'Welcome to MyBank - Online Banking Platform For You',
'https://www.mybank.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('MyBank');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['MyBank', 'Banking Platform For You', 'mybank.com']);
});
- it('should extract service name from title without divider', () => {
+ it('should extract service name from title without divider and include domain', () => {
const { document, location } = createTestDocument(
'GitHub: Let\'s build from here',
'https://github.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('GitHub');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['GitHub', 'Let\'s build from here', 'github.com']);
});
- it('should handle titles with multiple meaningful words', () => {
+ it('should handle titles with multiple meaningful words and include domain', () => {
const { document, location } = createTestDocument(
'Amazon Shopping Cart',
'https://www.amazon.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('Amazon Shopping');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Amazon Shopping', 'amazon.com']);
});
- it('should fall back to domain name when title has no meaningful words', () => {
+ it('should return only domain name when title has no meaningful words', () => {
const { document, location } = createTestDocument(
'Home | Welcome',
'https://www.example.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('example.com');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['example.com']);
});
- it('should handle titles with special characters', () => {
+ it('should handle titles with special characters and include domain', () => {
const { document, location } = createTestDocument(
'Netflix - Watch TV Shows Online, Watch Movies Online',
'https://www.netflix.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('Netflix');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Netflix', 'netflix.com']);
});
- it('should handle titles with multiple dividers', () => {
+ it('should handle titles with multiple dividers and include domain', () => {
const { document, location } = createTestDocument(
'Twitter / X - Social Media Platform',
'https://twitter.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('Twitter');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Twitter', 'X - Social Media', 'twitter.com']);
});
- it('should handle empty titles', () => {
+ it('should handle empty titles by returning only domain', () => {
const { document, location } = createTestDocument(
'',
'https://www.example.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('example.com');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['example.com']);
});
- it('should handle titles with only stop words', () => {
+ it('should handle titles with only stop words by returning only domain', () => {
const { document, location } = createTestDocument(
'The and or but',
'https://www.example.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('example.com');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['example.com']);
});
});
\ No newline at end of file
diff --git a/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.nl.test.ts b/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.nl.test.ts
index a2151d8bb..005d8029d 100644
--- a/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.nl.test.ts
+++ b/browser-extension/src/utils/formDetector/__tests__/FormDetector.serviceName.nl.test.ts
@@ -3,75 +3,75 @@ import { createTestDocument } from './TestUtils';
import { FormDetector } from '../FormDetector';
describe('FormDetector.getSuggestedServiceName (Dutch)', () => {
- it('should extract service name from title with divider', () => {
+ it('should extract service name from title with divider and include domain', () => {
const { document, location } = createTestDocument(
'ING - Online Bankieren',
'https://www.ing.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('ING');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['ING', 'Bankieren', 'ing.nl']);
});
- it('should extract service name from title without divider', () => {
+ it('should extract service name from title without divider and include domain', () => {
const { document, location } = createTestDocument(
'Bol.com | De winkel van ons allemaal',
'https://www.bol.com'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('Bol.com');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Bol.com', 'bol.com']);
});
- it('should handle titles with multiple meaningful words', () => {
+ it('should handle titles with multiple meaningful words and include domain', () => {
const { document, location } = createTestDocument(
'Albert Heijn Online Boodschappen',
'https://www.ah.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('Albert Heijn Online Boodschappen');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Albert Heijn Online Boodschappen', 'ah.nl']);
});
- it('should fall back to domain name when title has no meaningful words', () => {
+ it('should return only domain name when title has no meaningful words', () => {
const { document, location } = createTestDocument(
'Home | Welkom',
'https://www.voorbeeld.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('voorbeeld.nl');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['voorbeeld.nl']);
});
- it('should handle titles with special characters', () => {
+ it('should handle titles with special characters and include domain', () => {
const { document, location } = createTestDocument(
'NS - Nederlandse Spoorwegen',
'https://www.ns.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('NS - Nederlandse Spoorwegen');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['Nederlandse Spoorwegen', 'ns.nl']);
});
- it('should handle titles with multiple dividers', () => {
+ it('should handle titles with multiple dividers and include domain', () => {
const { document, location } = createTestDocument(
'KPN / Internet & TV',
'https://www.kpn.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('KPN');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['KPN', 'Internet & TV', 'kpn.nl']);
});
- it('should handle empty titles', () => {
+ it('should handle empty titles by returning only domain', () => {
const { document, location } = createTestDocument(
'',
'https://www.voorbeeld.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('voorbeeld.nl');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['voorbeeld.nl']);
});
- it('should handle titles with only Dutch stop words', () => {
+ it('should handle titles with only Dutch stop words by returning only domain', () => {
const { document, location } = createTestDocument(
'Je in op de',
'https://www.voorbeeld.nl'
);
- const serviceName = FormDetector.getSuggestedServiceName(document, location);
- expect(serviceName).toBe('voorbeeld.nl');
+ const suggestions = FormDetector.getSuggestedServiceName(document, location);
+ expect(suggestions).toEqual(['voorbeeld.nl']);
});
});
\ No newline at end of file