1

I am making a countdown timer chrome extension using mv3. The problem is if I use the setInterval or setTimeout method in a service worker, chrome suspends the service worker after 20s or above.

I've tried to use chrome.storage.local.onChanged api to add a listener and inside that listener I've used setTimeout method and updated the countdown timer after 1s, but still chrome suspends the servicer worker.

I don't want to use timers in the content scripts because then again I've to keep syncing the timers and if there are 100 tabs opened this will be not efficient.

If anyone have simple and efficient solution, kindly help me

Mohsin Ali
  • 360
  • 2
  • 12
  • There's no solution in MV3. The only workaround is to prolong the lifetime of the background script using a runtime port, [example](https://stackoverflow.com/a/66618269). – wOxxOm Feb 26 '22 at 18:02
  • ok, what method would you recommend? – Mohsin Ali Feb 27 '22 at 09:05
  • 1
    As you see you can only prolong the worker or use timers in the content scripts. Note that the site can clear the timers because they're not isolated. Both methods aren't ideal. MV3 has destroyed your extension. – wOxxOm Feb 27 '22 at 13:39

0 Answers0