Skip to content

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

Move alarm handler to top-level scope to improve reliability

Leendert de Borsta79bc8e020cb
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.ts
index 42ecdbf19..5d6d85f74 100644
--- a/apps/browser-extension/src/entrypoints/background.ts
+++ b/apps/browser-extension/src/entrypoints/background.ts
@@ -20,6 +20,15 @@ import type { SavePromptPersistedState, LastAutofilledCredential } from "@/utils
import { defineBackground, browser } from '#imports';
+/*
+ * Register alarm listener at top-level scope.
+ * [..] Move the event listener registration to the top level of your script.
+ * This ensures that Chrome will be able to immediately find and invoke your action's click handler,
+ * even if your extension hasn't finished executing its startup logic. [..]
+ * See: https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers
+ */
+browser.alarms.onAlarm.addListener(handleAutoLockAlarm);
+
export default defineBackground({
/**
* This is the main entry point for the background script.
@@ -129,12 +138,10 @@ export default defineBackground({
/*
* Initialize auto-lock alarm system.
* This ensures the alarm is restored if the service worker was terminated.
+ * Note: The alarm listener is registered at top-level scope (see above).
*/
await initializeAutoLockAlarm();
- // Register alarm listener for auto-lock
- browser.alarms.onAlarm.addListener(handleAutoLockAlarm);
-
// Listen for custom commands
try {
browser.commands.onCommand.addListener(async (command) => {