Skip to content

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

Merge branch 'main' into 798-browser-extension-make-service-name-extraction-more-accurate

Leendert de Borst0a0bec99b136
diff --cc browser-extension/src/utils/formDetector/FormDetector.ts
index 6dc367aff,c1d544feb..345ddb9b2
--- a/browser-extension/src/utils/formDetector/FormDetector.ts
+++ b/browser-extension/src/utils/formDetector/FormDetector.ts
@@@ -18,141 -18,6 +18,150 @@@ export class FormDetector
this.visibilityCache = new Map();
}
+ /**
+ * Detect login forms on the page based on the clicked element.
+ */
+ public containsLoginForm(): boolean {
- const formWrapper = this.clickedElement?.closest('form') ?? this.document.body;
++ let formWrapper = this.clickedElement?.closest('form, [role="dialog"]') as HTMLElement | null;
++ if (formWrapper?.getAttribute('role') === 'dialog') {
++ // If we hit a dialog, search for form only within the dialog
++ formWrapper = formWrapper.querySelector('form') as HTMLElement | null ?? formWrapper;
++ }
++
++ if (!formWrapper) {
++ // If no form or dialog found, fallback to document.body
++ formWrapper = this.document.body as HTMLElement;
++ }
+
+ /**
+ * Sanity check: if form contains more than 150 inputs, don't process as this is likely not a login form.
+ * This is a simple way to prevent processing large forms that are not login forms and making the browser page unresponsive.
+ */
+ const inputCount = formWrapper.querySelectorAll('input').length;
+ if (inputCount > 200) {
+ return false;
+ }
+
+ // Check if the wrapper contains a password or likely username field before processing.
+ if (this.containsPasswordField(formWrapper) || this.containsLikelyUsernameOrEmailField(formWrapper)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Detect login forms on the page based on the clicked element.
+ */
+ public getForm(): FormFields | null {
+ if (!this.clickedElement) {
+ return null;
+ }
+
+ const formWrapper = this.clickedElement.closest('form') ?? this.document.body;
+ return this.detectFormFields(formWrapper);
+ }
+
+ /**
+ * 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[] {
+ const title = document.title;
+ const maxWords = 4;
+ const maxLength = 50;
+
+ /**
+ * We apply a limit to the length and word count of the title to prevent
+ * the service name from being too long or containing too many words which
+ * is not likely to be a good service name.
+ */
+ const validLength = (text: string): boolean => {
+ const validLength = text.length >= 3 && text.length <= maxLength;
+ const validWordCount = text.split(/[\s|\-—/\\]+/).length <= maxWords;
+ return validLength && validWordCount;
+ };
+
+ /**
+ * Filter out common words from prefix/suffix until no more matches found
+ */
+ const getMeaningfulTitleParts = (title: string): string[] => {
+ const words = title.toLowerCase().split(' ').map(word => word.toLowerCase());
+
+ // Strip stopwords from start until no more matches
+ let startIndex = 0;
+ while (startIndex < words.length && CombinedStopWords.has(words[startIndex].toLowerCase())) {
+ startIndex++;
+ }
+
+ // Strip stopwords from end until no more matches
+ let endIndex = words.length - 1;
+ while (endIndex > startIndex && CombinedStopWords.has(words[endIndex].toLowerCase())) {
+ endIndex--;
+ }
+
+ // Return remaining words
+ return words.slice(startIndex, endIndex + 1);
+ };
+
+ /**
+ * Get original case version of meaningful words
+ */
+ const getOriginalCase = (text: string, meaningfulParts: string[]): string => {
+ return text
+ .split(/[\s|]+/)
+ .filter(word => meaningfulParts.includes(word.toLowerCase()))
+ .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);
+ if (dividerMatch) {
+ const dividerIndex = dividerMatch.index;
+ const beforeDivider = title.substring(0, dividerIndex).trim();
+ const afterDivider = title.substring(dividerIndex + 1).trim();
+
+ // Count meaningful words on each side
+ const beforeWords = getMeaningfulTitleParts(beforeDivider);
+ const afterWords = getMeaningfulTitleParts(afterDivider);
+
+ // 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);
+
+ // 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];
+ }
+ }
+
+ // If no meaningful parts found after divider, try the full title
+ const meaningfulParts = getMeaningfulTitleParts(title);
+ const serviceName = getOriginalCase(title, meaningfulParts);
+ if (validLength(serviceName)) {
+ return [serviceName, domainSuggestion];
+ }
+
+ // Fall back to domain name
+ return [domainSuggestion];
+ }
+
/**
* Check if an element and all its parents are visible.
* This checks for display:none, visibility:hidden, and opacity:0
diff --cc docs/misc/dev/browser-extensions.md
index acd395b02,7369a33a0..1d95aa0e6
--- a/docs/misc/dev/browser-extensions.md
+++ b/docs/misc/dev/browser-extensions.md
@@@ -105,11 -105,12 +105,11 @@@ The following websites have been known
| Website | Reason |
| --- | --- |
-| https://www.paprika-shopping.nl/nieuwsbrief/newsletter-register-landing.html | Popup CSS style conflicts |
-| https://bloshing.com/inschrijven-nieuwsbrief | Popup CSS style conflicts |
-| https://gamefaqs.gamespot.com/user | Popup buttons not working |
-| https://news.ycombinator.com/login?goto=news | Popup and client favicon not showing due to SVG format |
-| https://vault.bitwarden.com/#/login | Autofill password not detected (input not long enough), manually typing in works |
-| https://login.microsoftonline.com/ | Password gets reset after autofill |
-| https://mijn.ing.nl/login/ | Autofill doesn't detect input fields and AliasVault autofill icon placement is off |
-| https://github.com/lanedirt/AliasVault/issues | The "New issue -> Blank Issue" title field causes the autofill to trigger because of a parent form (outside of the role=modal div) |
-
+| [Paprika Shopping](https://www.paprika-shopping.nl/nieuwsbrief/newsletter-register-landing.html) | Popup CSS style conflicts |
+| [Bloshing](https://bloshing.com/inschrijven-nieuwsbrief) | Popup CSS style conflicts |
+| [GameFAQs](https://gamefaqs.gamespot.com/user) | Popup buttons not working |
+| [Hacker News](https://news.ycombinator.com/login?goto=news) | Popup and client favicon not showing due to SVG format |
+| [Bitwarden](https://vault.bitwarden.com/#/login) | Autofill password not detected (input not long enough), manually typing in works |
+| [Microsoft Online](https://login.microsoftonline.com/) | Password gets reset after autofill |
+| [ING Bank](https://mijn.ing.nl/login/) | Autofill doesn't detect input fields and AliasVault autofill icon placement is off |
-
++| [GitHub Issues](https://github.com/lanedirt/AliasVault/issues) | The "New issue -> Blank Issue" title field causes the autofill to trigger because of a parent form (outside of the role=modal div) |