Guidance for MV3: Persistent Service Workers..

715 views
Skip to first unread message

Sonny Chee

unread,
Jul 13, 2022, 10:30:45 PM7/13/22
to Chromium Extensions
Hey Guys,

I've used the technique described in the following link to make my service worker presistent.

https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension

If the service worker is persistent does that mean in-memory variables no longer need to be cached to disk?

wOxxOm

unread,
Jul 14, 2022, 4:36:59 AM7/14/22
to Chromium Extensions, sonny...@gmail.com
You still need it because there's no such thing as a persistent service worker and those workarounds have limits as described in the page you've linked, so the worker can terminate. You can maintain the state in a storage like chrome.storage.session if 1MB is sufficient or chrome.storage.local or IndexedDB for types like Blob, ArrayBuffer, UInt8Array.

Note that you shouldn't use that workaround just to simplify state management. Use it only to undo the performance dip incurred by restarting the worker in case your state is very expensive to rebuild or if you hook into frequent events that cause the worker to restart hundreds of times a day, which wastes orders of magnitude more resources than keeping a persistent worker in idle state.
Reply all
Reply to author
Forward
0 new messages