Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Fix merge conflicts (#2159)
Leendert de Borstc14d9479f098
diff --cc apps/browser-extension/src/entrypoints/background/VaultMessageHandler.tsindex 86cac5a9a,c89a67549..204af12ee--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts@@@ -23,23 -21,17 +23,23 @@@ import { AppErrorCode, formatErrorWithCimport { NetworkError } from '@/utils/types/errors/NetworkError';import { PayloadTooLargeError } from '@/utils/types/errors/PayloadTooLargeError';import { RequestTimeoutError } from '@/utils/types/errors/RequestTimeoutError';+import { ServerUpdateRequiredError } from '@/utils/types/errors/ServerUpdateRequiredError';import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';- import { BoolResponse as messageBoolResponse } from '@/utils/types/messaging/BoolResponse';+ import type { BoolResponse as messageBoolResponse } from '@/utils/types/messaging/BoolResponse';import type { DuplicateCheckResponse } from '@/utils/types/messaging/DuplicateCheckResponse';- import { IdentitySettingsResponse } from '@/utils/types/messaging/IdentitySettingsResponse';- import { ItemsResponse as messageItemsResponse } from '@/utils/types/messaging/ItemsResponse';- import { PasswordSettingsResponse as messagePasswordSettingsResponse } from '@/utils/types/messaging/PasswordSettingsResponse';+ import type { IdentitySettingsResponse } from '@/utils/types/messaging/IdentitySettingsResponse';+ import type { ItemsResponse as messageItemsResponse } from '@/utils/types/messaging/ItemsResponse';+ import type { PasswordSettingsResponse as messagePasswordSettingsResponse } from '@/utils/types/messaging/PasswordSettingsResponse';import type { SaveLoginResponse } from '@/utils/types/messaging/SaveLoginResponse';- import { StringResponse as stringResponse } from '@/utils/types/messaging/StringResponse';- import { VaultResponse as messageVaultResponse } from '@/utils/types/messaging/VaultResponse';- import { VaultUploadResponse as messageVaultUploadResponse } from '@/utils/types/messaging/VaultUploadResponse';+ import type { StringResponse as stringResponse } from '@/utils/types/messaging/StringResponse';+ import type { VaultResponse as messageVaultResponse } from '@/utils/types/messaging/VaultResponse';+ import type { VaultUploadResponse as messageVaultUploadResponse } from '@/utils/types/messaging/VaultUploadResponse';+import { type VaultMutationScope, ALL_VAULT_MUTATION_SCOPES, DEFAULT_VAULT_MUTATION_SCOPE, isManifestScope } from '@/utils/types/VaultMutationScope';+import { VaultCodec } from '@/utils/VaultCodec';+import { VaultKeyService } from '@/utils/VaultKeyService';+import { vaultRequiresManifestMigration } from '@/utils/VaultManifestMigration';import { vaultMergeService } from '@/utils/VaultMergeService';+import { vaultSyncService, invalidateCanonicalizeCache } from '@/utils/VaultSyncService';import { WebApiService } from '@/utils/WebApiService';import { t } from '@/i18n/StandaloneI18n';diff --cc apps/browser-extension/src/entrypoints/popup/components/LanguageSwitcher.tsxindex 4ea6cbc59,0573c0085..36c9cf02c--- a/apps/browser-extension/src/entrypoints/popup/components/LanguageSwitcher.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/LanguageSwitcher.tsx@@@ -1,9 -1,7 +1,9 @@@import React, { useState, useEffect, useRef } from 'react';import { useTranslation } from 'react-i18next';+import { StorageKeys } from '@/utils/constants/storageKeys';+- import { AVAILABLE_LANGUAGES, getLanguageConfig, ILanguageConfig } from '../../../i18n/config';+ import { AVAILABLE_LANGUAGES, getLanguageConfig, type ILanguageConfig } from '../../../i18n/config';import { storage } from '#imports';diff --cc apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsxindex abcd3d48b,60cd536bc..48f77ed28--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx@@@ -35,8 -34,8 +35,9 @@@ import { FieldCategories, FieldTypes, Limport { FaviconService } from '@/utils/FaviconService';import { LocalPreferencesService } from '@/utils/LocalPreferencesService';import { sendMessage } from '@/utils/messaging/ExtensionMessaging';+ import { NavigationStateService } from '@/utils/NavigationStateService';import * as RustCore from '@/utils/RustCore';+import SqliteClient from '@/utils/SqliteClient';import { browser } from '#imports';diff --cc apps/browser-extension/src/utils/NavigationStateService.tsindex 000000000,9d2c86f4e..fbe176032mode 000000,100644..100644--- a/apps/browser-extension/src/utils/NavigationStateService.ts+++ b/apps/browser-extension/src/utils/NavigationStateService.ts@@@ -1,0 -1,70 +1,62 @@@-import { storage } from '#imports';++import { StorageKeys } from '@/utils/constants/storageKeys';+-/**- * Storage keys for the popup navigation state that is persisted across popup opens.- */-export const NAVIGATION_STATE_KEYS = {- LAST_VISITED_PAGE: 'session:lastVisitedPage',- LAST_VISITED_TIME: 'session:lastVisitedTime',- NAVIGATION_HISTORY: 'session:navigationHistory',- LAST_TAB_URL: 'session:lastTabUrl',-} as const;++import { storage } from '#imports';++ /**+ * A single entry in the persisted popup navigation history.+ */+ export type NavigationHistoryEntry = {+ pathname: string;+ search: string;+ hash: string;+ };++ /**+ * Service for reading and clearing the persisted popup navigation state (last visited page + history).+ */+ export const NavigationStateService = {+ /**+ * Persist the current page, visit time and navigation history.+ */+ async storeNavigationState(pathname: string, historyEntries: NavigationHistoryEntry[]): Promise<void> {+ await Promise.all([- storage.setItem(NAVIGATION_STATE_KEYS.LAST_VISITED_PAGE, pathname),- storage.setItem(NAVIGATION_STATE_KEYS.LAST_VISITED_TIME, Date.now()),- storage.setItem(NAVIGATION_STATE_KEYS.NAVIGATION_HISTORY, historyEntries),++ storage.setItem(StorageKeys.LAST_VISITED_PAGE, pathname),++ storage.setItem(StorageKeys.LAST_VISITED_TIME, Date.now()),++ storage.setItem(StorageKeys.NAVIGATION_HISTORY, historyEntries),+ ]);+ },++ /**+ * Get the persisted navigation state (last visited page, visit time and history).+ */+ async getNavigationState(): Promise<{ lastPage: string | null, lastVisitTime: number | null, history: NavigationHistoryEntry[] | null }> {+ const [lastPage, lastVisitTime, history] = await Promise.all([- storage.getItem(NAVIGATION_STATE_KEYS.LAST_VISITED_PAGE) as Promise<string | null>,- storage.getItem(NAVIGATION_STATE_KEYS.LAST_VISITED_TIME) as Promise<number | null>,- storage.getItem(NAVIGATION_STATE_KEYS.NAVIGATION_HISTORY) as Promise<NavigationHistoryEntry[] | null>,++ storage.getItem(StorageKeys.LAST_VISITED_PAGE) as Promise<string | null>,++ storage.getItem(StorageKeys.LAST_VISITED_TIME) as Promise<number | null>,++ storage.getItem(StorageKeys.NAVIGATION_HISTORY) as Promise<NavigationHistoryEntry[] | null>,+ ]);+ return { lastPage, lastVisitTime, history };+ },++ /**+ * Clear the persisted navigation state so the next popup open starts fresh instead of restoring the last page.+ * Keeps the last tab URL, which is used separately for tab-switch detection.+ */+ async clearNavigationState(): Promise<void> {- await storage.removeItems([NAVIGATION_STATE_KEYS.LAST_VISITED_PAGE, NAVIGATION_STATE_KEYS.LAST_VISITED_TIME, NAVIGATION_STATE_KEYS.NAVIGATION_HISTORY]);++ await storage.removeItems([StorageKeys.LAST_VISITED_PAGE, StorageKeys.LAST_VISITED_TIME, StorageKeys.NAVIGATION_HISTORY]);+ },++ /**+ * Get the last known browser tab URL, used to detect tab switches between popup opens.+ */+ async getLastTabUrl(): Promise<string | null> {- return await storage.getItem(NAVIGATION_STATE_KEYS.LAST_TAB_URL) as string | null;++ return await storage.getItem(StorageKeys.LAST_TAB_URL) as string | null;+ },++ /**+ * Store the current browser tab URL for future tab-switch detection.+ */+ async setLastTabUrl(url: string): Promise<void> {- await storage.setItem(NAVIGATION_STATE_KEYS.LAST_TAB_URL, url);++ await storage.setItem(StorageKeys.LAST_TAB_URL, url);+ },+ };diff --cc apps/browser-extension/src/utils/ShadowDom.tsindex 000000000,379d10ecf..ef0af1dcamode 000000,100644..100644--- a/apps/browser-extension/src/utils/ShadowDom.ts+++ b/apps/browser-extension/src/utils/ShadowDom.ts@@@ -1,0 -1,223 +1,223 @@@+ /**+ * Helpers for working with pages that render (part of) their content inside open shadow roots.+ */+-import { devLog } from '@/utils/DevLogger';++import { devLog } from '@/utils/devLogger/DevLogger';++ /**+ * Upper bound on the number of shadow roots a single deep query descends into, to limit scans to+ * sane max values. Component-heavy pages are known to run well into the hundreds, therefore we+ * set this to a high value.+ */+ const MAX_SHADOW_ROOTS = 2000;++ /**+ * Get the shadow root a node lives in, or null when it is in the normal DOM.+ * @param node - The node to resolve the root for.+ * @returns The containing ShadowRoot, or null when the node is not inside a shadow root.+ */+ export function getContainingShadowRoot(node: Node | null): ShadowRoot | null {+ const root = node?.getRootNode() as ShadowRoot | undefined;+ return root?.host ? root : null;+ }++ /**+ * Get the root node (Document or ShadowRoot) a node belongs to.+ * @param node - The node to resolve the root for.+ * @returns The node's Document or ShadowRoot.+ */+ export function getQueryRoot(node: Node): Document | ShadowRoot {+ return node.getRootNode() as Document | ShadowRoot;+ }++ /**+ * Like `Element.parentElement`, but hops from the top of a shadow root to its host element+ * instead of returning null.+ * @param element - The element to get the parent of.+ * @returns The parent element in the composed tree, or null at the top of the root node.+ */+ export function getComposedParentElement(element: Element | null): Element | null {+ if (!element) {+ return null;+ }++ if (element.parentElement) {+ return element.parentElement;+ }++ return getContainingShadowRoot(element)?.host ?? null;+ }++ /**+ * Collect the shadow hosts an element sits inside, innermost first.+ * @param element - The element to resolve the hosts for.+ * @param maxDepth - Maximum number of hosts to walk up to.+ * @returns The shadow hosts wrapping the element, innermost first; empty when it is not in a shadow tree.+ */+ export function getShadowHostChain(element: Element | null, maxDepth: number = 3): Element[] {+ const hosts: Element[] = [];+ let current: Element | null = element;++ while (current && hosts.length < maxDepth) {+ const host = getContainingShadowRoot(current)?.host ?? null;+ if (!host) {+ break;+ }++ hosts.push(host);+ current = host;+ }++ return hosts;+ }++ /**+ * Similar to `Element.closest()`, but continues the search at the shadow host when the element's own shadow root contains no match.+ * @param element - The element to start searching from.+ * @param selector - The CSS selector to match against.+ * @returns The nearest matching ancestor in the composed tree, or null when there is none.+ */+ export function closestAcrossShadow(element: Element | null, selector: string): HTMLElement | null {+ let current: Element | null = element;++ while (current) {+ const match = current.closest(selector) as HTMLElement | null;+ if (match) {+ return match;+ }+ current = getContainingShadowRoot(current)?.host ?? null;+ }++ return null;+ }++ /**+ * Similar to `Node.contains()`, but treats a shadow host as containing its shadow root.+ * @param ancestor - The candidate ancestor element.+ * @param node - The node to test.+ * @returns True when node is ancestor itself or sits below it in the composed tree.+ */+ export function composedContains(ancestor: Element | null, node: Node | null): boolean {+ if (!ancestor || !node) {+ return false;+ }++ let current: Node | null = node;+ while (current) {+ if (current === ancestor) {+ return true;+ }++ // At the top of a shadow tree parentNode is the ShadowRoot itself — continue at its host.+ const parent = current.parentNode as (Node & { host?: Element }) | null;+ current = parent ? (parent.host ?? parent) : null;+ }++ return false;+ }++ /**+ * Resolve the element a focus/pointer event really originated from, looking through shadow+ * boundaries. Events crossing an open shadow root are retargeted to the host, so `event.target`+ * alone would report the custom element instead of the input the user actually focused.+ * @param event - The event to resolve the target for.+ * @returns The deepest element in the event's composed path, falling back to `event.target`.+ */+ export function getDeepEventTarget(event: Event): Element | null {+ const path = typeof event.composedPath === 'function' ? event.composedPath() : [];+ const deepest = path[0] as Element | undefined;++ // Node.ELEMENT_NODE — duck-typed so it also holds for nodes from another realm.+ if (deepest && deepest.nodeType === 1) {+ return deepest;+ }++ return event.target as Element | null;+ }++ /**+ * Resolve the focused element, descending through open shadow roots. `document.activeElement`+ * only reports the outermost host for content inside a shadow tree.+ * @param documentOrRoot - The document (or shadow root) to start from.+ * @returns The deepest focused element, or null when nothing is focused.+ */+ export function getDeepActiveElement(documentOrRoot: Document | ShadowRoot): Element | null {+ let active = documentOrRoot.activeElement;++ while (active?.shadowRoot?.activeElement) {+ active = active.shadowRoot.activeElement;+ }++ return active;+ }++ /**+ * Collect every open shadow root reachable from the given root.+ * @param root - The root to scan.+ * @returns The reachable shadow roots, outermost first.+ */+ export function collectShadowRoots(root: Document | ShadowRoot | Element): ShadowRoot[] {+ const shadowRoots: ShadowRoot[] = [];+ const seen = new Set<ShadowRoot>();+ const queue: (Document | ShadowRoot | Element)[] = [root];++ while (queue.length > 0 && shadowRoots.length < MAX_SHADOW_ROOTS) {+ const current = queue.shift()!;++ for (const element of Array.from(current.querySelectorAll<HTMLElement>('*'))) {+ const shadowRoot = element.shadowRoot;+ if (shadowRoot && !seen.has(shadowRoot)) {+ seen.add(shadowRoot);+ shadowRoots.push(shadowRoot);+ queue.push(shadowRoot);++ if (shadowRoots.length >= MAX_SHADOW_ROOTS) {+ devLog(`[ShadowDom] Shadow root scan truncated at ${MAX_SHADOW_ROOTS} roots; deeper components are not visible to detection.`);+ break;+ }+ }+ }+ }++ return shadowRoots;+ }++ /**+ * Similar to `querySelectorAll`, but also descends into open shadow roots.+ * @param root - The root to query from.+ * @param selector - The CSS selector to match.+ * @returns The matching elements from the normal DOM and every reachable shadow root.+ */+ export function queryAllDeep<T extends Element>(root: Document | ShadowRoot | Element, selector: string): T[] {+ const results: T[] = Array.from(root.querySelectorAll<T>(selector));++ for (const shadowRoot of collectShadowRoots(root)) {+ results.push(...Array.from(shadowRoot.querySelectorAll<T>(selector)));+ }++ return results;+ }++ /**+ * Like `document.getElementById`, but also searches open shadow roots. IDs inside a shadow tree+ * are scoped to that tree, so the same id may legitimately exist more than once; the normal DOM+ * match wins, then shadow trees in document order.+ * @param documentOrRoot - The document to search.+ * @param elementId - The id to look for.+ * @returns The first matching element, or null when there is none.+ */+ export function getDeepElementById(documentOrRoot: Document | ShadowRoot, elementId: string): HTMLElement | null {+ const lightMatch = documentOrRoot.getElementById(elementId) as HTMLElement | null;+ if (lightMatch) {+ return lightMatch;+ }++ for (const shadowRoot of collectShadowRoots(documentOrRoot)) {+ const match = shadowRoot.getElementById(elementId);+ if (match) {+ return match as HTMLElement;+ }+ }++ return null;+ }diff --cc apps/browser-extension/src/utils/formDetector/FormDetector.tsindex 20f03a456,85ec0708f..35d8aaf7f--- a/apps/browser-extension/src/utils/formDetector/FormDetector.ts+++ b/apps/browser-extension/src/utils/formDetector/FormDetector.ts@@@ -1,7 -1,8 +1,8 @@@-import { devLog } from "@/utils/DevLogger";+import { devLog } from "@/utils/devLogger/DevLogger";+ import { closestAcrossShadow, collectShadowRoots, getComposedParentElement, getQueryRoot, getShadowHostChain, queryAllDeep } from "@/utils/ShadowDom";- import { CombinedEmailVerificationPatterns, CombinedFieldExclusionPatterns, CombinedFieldPatterns, CombinedGenderOptionPatterns, CombinedStopWords, FieldPatternEntry, includeTerms, specificIncludeTerms } from "./FieldPatterns";- import { DetectedFieldType, FormFields } from "./types/FormFields";+ import { CombinedEmailVerificationPatterns, CombinedFieldExclusionPatterns, CombinedFieldPatterns, CombinedGenderOptionPatterns, CombinedStopWords, type FieldPatternEntry, includeTerms, specificIncludeTerms } from "./FieldPatterns";+ import { DetectedFieldType, type FormFields } from "./types/FormFields";/*** Short human-readable identifier for an element, used in devLog traces.