2

I have an existing Auto-reload Chrome extension using manifest version 2. It is achieved by using a background page with persistent: true so a setInterval can run indefinitely. Chrome is phasing out MV2 soon so I want to upgrade it realized it's difficult with service worker replacement.

  • The Service Worker would become inactive after about 30 seconds so setTimeout or setInterval is out of question.

  • chrome.alarms only run once every minute and with inaccuracies. My extension provides options under a minute like 10s or 30s.

What is a solution for a general frequent timer like my case?

Luke Vo
  • 17,859
  • 21
  • 105
  • 181
  • 1
    There's no solution. The workaround is to [keep the worker running](https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension/66618269). – wOxxOm Jan 12 '22 at 17:11
  • @wOxxOm Thanks, I found that article after the question as well. I am also trying my own approach similar to that but in my specific case I have access to `activeTab` and only need to keep it awake as long as the tab is still active. – Luke Vo Jan 12 '22 at 17:22
  • Interesting, I had made a similar personal v2 reload extension and was looking at migrating to v3 and have hit the same concern. I have since mostly been using FF, which only supported v2 until somewhat recently. I wanted to update to v3 manifest so that I could maintain my dual compatibility with both browsers. Chrome does seem to have "offscreen" documents which sound like they might be able to manage the timeout calls to push timely events. But this is not available in FF. https://github.com/w3c/webextensions/issues/170 – Jeff Adamson Mar 15 '23 at 13:14
  • @JeffAdamson I had to upgrade many other extensions, some of which also need an active tab present (for example, for modifying Audio Context). Unfortunately the general solution is to launch a window and user has to keep it open as long as they want the app to be functional. – Luke Vo Mar 15 '23 at 13:17

0 Answers0