The message in the console is not an error. Service worker registration successful followed by silence is the designed behavior of Manifest V3, and the sooner that stops feeling like a crash, the sooner the bugs get easier.

These are the questions I answer most often, in the order they usually arrive.

The short version

  • The worker is supposed to stop when idle; that is not a failure.
  • Logs vanish because each worker gets a fresh console, not because logging broke.
  • Persist deadlines and job records; do not try to make the process immortal.

"Why does it stop after 30 seconds?"

Chrome terminates an idle background service worker after roughly 30 seconds without extension events. A single event may run for up to five minutes, but a pending setTimeout does not count as activity. The worker is a request handler, not a daemon.

"Is it crashing?"

Usually not. Open chrome://serviceworker-internals, find your extension, and read the lifecycle entries. A normal stop says the worker became idle and was terminated; a crash includes an error and a stack. If you see no exception, you are looking at the lifecycle doing its job.

"Why do my logs disappear?"

Each worker incarnation starts with a fresh console. If you only log to console.log, the previous incarnation's output is gone when the new one starts.

Write a boot marker to storage instead:

const bootId = crypto.randomUUID(); await chrome.storage.session.set({ lastBoot: { id: bootId, at: Date.now() } }); console.log('worker boot', bootId); 

Now the popup, or a debug page, can show how many times the worker restarted and when. That single field explains most "it randomly resets" reports.

"It stops even with the popup open. Why?"

The popup is a separate context. While it is open, messages and port connections can keep the worker alive, but closing the popup ends that. A long-running job that only worked while the popup was open was never a background job.

"Can I make the worker persistent?"

There is no supported way. Keepalive loops — a message every 20 seconds, an offscreen document created for no reason, a silent audio element — are detectable, burn battery, and are exactly what the platform was designed to prevent. They postpone termination; they do not survive a browser restart or a suspension.

"Why does it wake for some events but not my timer?"

Events that wake the worker include runtime messages, action clicks, alarms, web navigation, storage changes from other contexts and install/startup events. A timer callback is not an event; it is a callback in a heap that no longer exists. Alarms are the bridge between "later" and "an event".

"How do I know it restarted, not re-ran?"

Use a boot id and a sequence number per job. If the job record shows attempts: 2 and the boot id changed between them, you have proof of a restart. Without that, you are guessing from timestamps.

"What should I persist?"

Deadlines, job identity, status and attempt counts. Not remaining seconds, not interval handles, not "isRunning" booleans without a lock timeout. The full model is a small record, and it is cheaper than every workaround combined.

A symptom-to-cause table

Symptom Likely cause
Counter resets to zero Value lived only in the heap
Timer never fires setTimeout outlived the worker
Timer fires twice Alarm retried, executor not idempotent
Logs stop mid-flow Worker terminated, new console
Works in dev, fails in prod Devtools or another extension kept it awake

The part that is genuinely annoying

Alarms are approximate and have a 30-second floor, so a feature that needs exact sub-minute scheduling without an open UI has no good answer in MV3. That is a real product constraint, not a misunderstanding.

vite-mv3-sw-compile-persist softens the migration: long timers become alarm-backed wrappers and marked state is restored before handlers run. It does not make the worker persistent, does not support destructured state, and cannot recover anonymous callbacks that captured locals. Anyone promising otherwise is selling a keepalive hack with better branding.

Keep the record small; a large blob read on every wake costs more than the bug it prevents.

With and without the plugin

The before/after from the plugin's README is the whole argument:

Without vite-mv3-sw-compile-persist

let count = 0; chrome.action.onClicked.addListener(async () => { const stored = await chrome.storage.session.get('count'); count = (stored.count as number) ?? 0; count++; await chrome.storage.session.set({ count }); }); chrome.alarms.create('cleanup', { delayInMinutes: 5 }); chrome.alarms.onAlarm.addListener((alarm) => { if (alarm.name === 'cleanup') cleanup(); }); 

With vite-mv3-sw-compile-persist

let count = 0; chrome.action.onClicked.addListener(() => { count++; }); setTimeout(cleanup, 5 * 60_000); 

The second version is the code you meant to write. The plugin adds restore, dirty tracking, a debounced flush and alarm-backed timers at build time — no runtime import, no wrapper API.

Repository: vite-mv3-sw-compile-persist

If these answers replaced a week of console archaeology, a star on the repo is a reasonable way to say so.

Which symptom sent you looking for this page in the first place?