0

This is my first chrome extension using manifest v3, and I want to make a timer in it.

This is supposed to update every second, and not run on any specific tab nor the popup window.

I tried to do this in my service worker:

let counter = 0
setInterval(() => {
    counter++
}, 1000)

But that didn't work well, because after around half a minute, the service worker would go "inactive", and thus stop this loop.

So I am just looking for a way to make a loop that executes some code every 1 second. This loop always has to be running. And I do not really have a way to "launch" say a function every second from another page. I can start it once, but because of the service worker that goes inactive after a while, then this script has to either just never die or relaunch itself every second.

Is this even possible?

Tobias H.
  • 319
  • 2
  • 13
  • 1
    Depending on how you use this counter there may be a solution but generally MV3 doesn't have one. The only workarounds are listed here: [Persistent Service Worker in Chrome Extension](https://stackoverflow.com/a/66618269) – wOxxOm Dec 30 '21 at 20:00

0 Answers0