Closed michielbdejong closed 3 years ago
If the background page is lazily loaded, perhaps making use of chrome.runtime.onStartup
will help ensure the fetch is done when the browser is restarted.
It really depends on how often the services data changes and should be resynchronised. Some users expect the browser to be very, very long lived: days, weeks, even months. They accumulate tens even hundreds of tabs open, thus making them even less inclined to restart the browser.
An alternative solution to the problem here is to use chrome.alarms
a rudimentary form of CRON jobs. They can be set to schedule running operations at some time in the future, though precision is not guaranteed.
Using chrome.alarms
requires the request of a new permission in the manifest: "alarms".
This solution may also serve #5 whereby an alarm can be scheduled to run every few minutes until a connection is established to the API, after which the alarm to sync the data can be set to a much less frequent cycle of maybe once per day or less.
it seems the background script is not run when closing and reopening the browser. this means
getServices
is not called often enough. will check for OS restart, but might require some other trigger.