Skip to content

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

Update browser extension dictionaries folder load (#581)

Leendert de Borstc476c53101cd
diff --git a/browser-extension/.gitignore b/browser-extension/.gitignore
index c2820a1d4..e8dff8f18 100644
--- a/browser-extension/.gitignore
+++ b/browser-extension/.gitignore
@@ -25,3 +25,9 @@ web-ext.config.ts
*.njsproj
*.sln
*.sw?
+
+# Dictionaries
+# During build these are copied from the ../dictionaries folder because firefox zip requires all files to be in the root of the zip.
+# Therefore this copied folder is not committed to the repo the original folder is already available outside this directory.
+# See vite-plugins/identity-gen-dict-loader.ts for more details.
+dictionaries
diff --git a/browser-extension/README.md b/browser-extension/README.md
index d73a2442b..5c4fde652 100644
--- a/browser-extension/README.md
+++ b/browser-extension/README.md
@@ -6,18 +6,13 @@ The browser extension is built using WXT and React:
To build the browser extension, run the following command in this directory:
+### Build the browser extension
```bash
npm install
# Build the Chrome extension (saves in dist/chrome-mv3)
-npm run build:chrome
+npm run zip:chrome
# Build the Firefox extension (saves in dist/firefox-mv2)
-npm run build:firefox
+npm run zip:firefox
```
-
-To load the browser extension in Chrome, follow these steps:
-
-1. Open Chrome and navigate to `chrome://extensions/`.
-2. Enable "Developer mode" if it is not already enabled.
-3. Click on "Load unpacked" and select the `dist/chrome-mv3` folder.
diff --git a/browser-extension/vite-plugins/identity-gen-dict-loader.ts b/browser-extension/vite-plugins/identity-gen-dict-loader.ts
index 93405403d..a8089c789 100644
--- a/browser-extension/vite-plugins/identity-gen-dict-loader.ts
+++ b/browser-extension/vite-plugins/identity-gen-dict-loader.ts
@@ -20,9 +20,38 @@ export default function identityGenDictLoader() {
const match = id.match(/IdentityGenerator([A-Za-z]{2})\.ts$/);
if (match) {
const lang = match[1].toLowerCase();
- const dictionaryPath = path.resolve(__dirname, '..', '..', 'dictionaries', lang);
+
+ // Define paths
+ const parentDictPath = path.resolve(__dirname, '..', '..', 'dictionaries');
+ const localDictPath = path.resolve(__dirname, '..', 'dictionaries');
+
+ // Ensure local dictionary directory exists
+ if (!fs.existsSync(localDictPath)) {
+ fs.mkdirSync(localDictPath, { recursive: true });
+ }
+
+ // Firefox requires the complete source code when submitting extensions.
+ // In our monorepo setup, dictionary files are stored at the root level
+ // to be shared across different packages. However, for Firefox submission,
+ // we need these dictionaries to be present within the browser-extension
+ // directory itself.
+
+ // Therefore, we first check if dictionaries exist in the parent (root) directory
+ // and copy them to the local browser-extension directory if found.
+ if (fs.existsSync(parentDictPath)) {
+ // Recursively copy the entire dictionaries folder
+ fs.cpSync(parentDictPath, localDictPath, {
+ recursive: true,
+ force: true
+ });
+ } else {
+ console.log('No parent dictionaries folder found, using local version instead. This is expected when running the firefox build separately.');
+ }
try {
+ // Use local dictionary path for reading files
+ const dictionaryPath = path.join(localDictPath, lang);
+
// Read dictionary files and clean up entries
const firstNamesMale = fs.readFileSync(path.join(dictionaryPath, 'firstnames_male'), 'utf-8')
.split('\n')
diff --git a/browser-extension/wxt.config.ts b/browser-extension/wxt.config.ts
index 8de99605d..ebe695bf8 100644
--- a/browser-extension/wxt.config.ts
+++ b/browser-extension/wxt.config.ts
@@ -45,4 +45,7 @@ export default defineConfig({
})
],
}),
+ zip: {
+ includeSources: ['dictionaries', 'README.md'],
+ },
});