How a build-time AST transform finally makes Manifest V3 state persistence painless
Manifest V3 didn’t just change the extension model — it actively punishes normal JavaScript patterns.
Your background service worker is killed after roughly 30 seconds of inactivity. When Chrome restarts it, every top-level let , every Map , every pending setTimeout is gone. The next event handler starts from a clean slate.
The official workaround is brutal:
Manually serialize every piece of state to chrome.storage
await it back on every event
Rewrite long-running timers as chrome.alarms
Maintain careful locking so concurrent restarts don’t cause duplicate work
The result is hundreds of lines of defensive plumbing that has nothing to do with your actual feature.
A different approach: transform the code, not the developer
vite-mv3-sw-compile-persist takes a build-time approach. You keep writing ordinary JavaScript.…