Open stroobandt opened 3 years ago
I actually tried to create a shim for delayed and recurring notification triggers. Here is how I did this:
A dedicated web worker runs the setTimeout
or setInterval
and sends its notification request messages to the core PWA client. The client relays these notification requests to the service worker which wakes up, deletes any previous notifications and finally shows the new notification.
This works perfectly on the Chrome desktop browser with the installed PWA running in a tab without focus and with DevTools closed, as this influences sleeping behaviour. Timers with 30 minute or longer intervals are no problem at all.
Unfortunately, this does not work with the Chrome browser for Android. The dedicated web worker gets put to sleep shortly after (about 5 minutes) moving the PWA to the background.
My questions are:
protected worker
.The Google Firestore team also seems to have issues with the lack of persistence in web workers.
It really looks like corporate Google engineers of different Google divisions are waging similar battles against a common problem.
The need for recurring triggers was clearly voiced in the feedback of the Chrome M80-M83 Origin Trial. I would like to echo this pressing need by presenting the following humanitarian use case.
As an international nonprofit organisation, we are currently developing a progressive web application (PWA) for researching the aetiology (origin) of a number of medical conditions in the setting of clinical trials.
Indefinitely recurring notification triggers would allow to remind patients to take their medicine or to fill in a form at specific times of the day.
The preceding notification(s) would be cleared prior to showing the new notification.
As this application is not intended for a general audience, it cannot be offered as a native app in the Google Play Store. Whereas to keep the barriers to installation low, we went for a PWA. A low barrier to unassisted installation is especially important right now during the ongoing SARS-CoV-2 pandemic, where interaction with patients and their smartphones or tablets should be kept to an absolute minimum. Nonetheless, non-COVID patients and their needs should not be left unattended during the current crisis.
For your information, there exists also a 2018 StackExchange question about this topic, which I recently answered to the best of my knowledge.
Slightly related, Manifest V3 for Chrome Extensions has a
chrome.alarms
API for service workers, as explained here. Obviously, this is of no use to the Android Chrome browser, but perhaps some ideas may be borrowed.