Skip to content

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

Add identity setting retrieval to content script (#861)

Leendert de Borst4422ddcaa3c4
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.ts
index b86548fb8..6efa48a02 100644
--- a/apps/browser-extension/src/entrypoints/background.ts
+++ b/apps/browser-extension/src/entrypoints/background.ts
@@ -2,7 +2,7 @@ import { onMessage, sendMessage } from "webext-bridge/background";
import { setupContextMenus } from '@/entrypoints/background/ContextMenu';
import { handleOpenPopup, handlePopupWithCredential, handleToggleContextMenu } from '@/entrypoints/background/PopupMessageHandler';
-import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleCreateIdentity, handleGetCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentityLanguage, handleGetDerivedKey, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreVault, handleSyncVault, handleUploadVault } from '@/entrypoints/background/VaultMessageHandler';
+import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleCreateIdentity, handleGetCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetDerivedKey, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreVault, handleSyncVault, handleUploadVault } from '@/entrypoints/background/VaultMessageHandler';
import { GLOBAL_CONTEXT_MENU_ENABLED_KEY } from '@/utils/Constants';
@@ -23,7 +23,7 @@ export default defineBackground({
onMessage('GET_CREDENTIALS', () => handleGetCredentials());
onMessage('CREATE_IDENTITY', ({ data }) => handleCreateIdentity(data));
onMessage('GET_DEFAULT_EMAIL_DOMAIN', () => handleGetDefaultEmailDomain());
- onMessage('GET_DEFAULT_IDENTITY_LANGUAGE', () => handleGetDefaultIdentityLanguage());
+ onMessage('GET_DEFAULT_IDENTITY_SETTINGS', () => handleGetDefaultIdentitySettings());
onMessage('GET_PASSWORD_SETTINGS', () => handleGetPasswordSettings());
onMessage('GET_DERIVED_KEY', () => handleGetDerivedKey());
onMessage('OPEN_POPUP', () => handleOpenPopup());
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index 5b6504bfa..bcd21dcea 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -6,6 +6,7 @@ import { EncryptionUtility } from '@/utils/EncryptionUtility';
import { SqliteClient } from '@/utils/SqliteClient';
import { BoolResponse as messageBoolResponse } from '@/utils/types/messaging/BoolResponse';
import { CredentialsResponse as messageCredentialsResponse } from '@/utils/types/messaging/CredentialsResponse';
+import { IdentitySettingsResponse } from '@/utils/types/messaging/IdentitySettingsResponse';
import { PasswordSettingsResponse as messagePasswordSettingsResponse } from '@/utils/types/messaging/PasswordSettingsResponse';
import { StoreVaultRequest } from '@/utils/types/messaging/StoreVaultRequest';
import { StringResponse as stringResponse } from '@/utils/types/messaging/StringResponse';
@@ -276,18 +277,25 @@ export function handleGetDefaultEmailDomain(): Promise<stringResponse> {
}
/**
- * Get the default identity language.
+ * Get the default identity settings.
*/
-export async function handleGetDefaultIdentityLanguage(
-) : Promise<stringResponse> {
+export async function handleGetDefaultIdentitySettings(
+) : Promise<IdentitySettingsResponse> {
try {
const sqliteClient = await createVaultSqliteClient();
- const settingValue = sqliteClient.getDefaultIdentityLanguage();
+ const language = sqliteClient.getDefaultIdentityLanguage();
+ const gender = sqliteClient.getDefaultIdentityGender();
- return { success: true, value: settingValue };
+ return {
+ success: true,
+ settings: {
+ language,
+ gender
+ }
+ };
} catch (error) {
- console.error('Error getting default identity language:', error);
- return { success: false, error: 'Failed to get default identity language' };
+ console.error('Error getting default identity settings:', error);
+ return { success: false, error: 'Failed to get default identity settings' };
}
}
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
index 3d533bb41..4c4ea3f11 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -10,6 +10,7 @@ import { CreatePasswordGenerator, PasswordGenerator } from '@/utils/dist/shared/
import { FormDetector } from '@/utils/formDetector/FormDetector';
import { SqliteClient } from '@/utils/SqliteClient';
import { CredentialsResponse } from '@/utils/types/messaging/CredentialsResponse';
+import { IdentitySettingsResponse } from '@/utils/types/messaging/IdentitySettingsResponse';
import { PasswordSettingsResponse } from '@/utils/types/messaging/PasswordSettingsResponse';
import { StringResponse } from '@/utils/types/messaging/StringResponse';
@@ -244,9 +245,9 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Creden
};
} else {
// Generate new random identity using identity generator.
- const identityLanguage = await sendMessage('GET_DEFAULT_IDENTITY_LANGUAGE', {}, 'background') as StringResponse;
- const identityGenerator = CreateIdentityGenerator(identityLanguage.value ?? 'en');
- const identity = identityGenerator.generateRandomIdentity();
+ const identitySettings = await sendMessage('GET_DEFAULT_IDENTITY_SETTINGS', {}, 'background') as IdentitySettingsResponse;
+ const identityGenerator = CreateIdentityGenerator(identitySettings.settings?.language ?? 'en');
+ const identity = identityGenerator.generateRandomIdentity(identitySettings.settings?.gender);
// Get password settings from background
const passwordSettingsResponse = await sendMessage('GET_PASSWORD_SETTINGS', {}, 'background') as PasswordSettingsResponse;
diff --git a/apps/browser-extension/src/utils/types/messaging/IdentitySettingsResponse.ts b/apps/browser-extension/src/utils/types/messaging/IdentitySettingsResponse.ts
new file mode 100644
index 000000000..a767eaf8c
--- /dev/null
+++ b/apps/browser-extension/src/utils/types/messaging/IdentitySettingsResponse.ts
@@ -0,0 +1,8 @@
+export type IdentitySettingsResponse = {
+ success: boolean,
+ error?: string,
+ settings?: {
+ language: string,
+ gender: string
+ }
+};