0

I have a PWA and send notifications at some events. I would like to give the user the opportunity to set the times at which they would like to receive push notifications. My plan was to save the received notifications in indexeddb if they arrive outside of the specified times and then to show them as soon as the user wants to receive messages.

Is this reasonably possible to build in the browser with js?

First of all I just wanted to create a setTimeout in the ServiceWorker, but I quickly realized that this is not a good idea.

After that I found this Stackoverflow post that recommends Notification Triggers. Also this tutorial (which comes first when you search the topic on Google) uses them. However, Chrome itself warns that it is no longer supported. In addition, it would only have been supported by Chrome, which is not enough for me anyway.

Another suggestion from the Stackoverflow post was the Periodic Background Sync API. It seems like a good workaround for the problem, but it only works in Chrome, so it's not enough for me either.

The only solution I can think of at the moment is the following: If the service worker shouldn't show a notification (because the user doesn't want one at that time), it sends my server a request to send back a web push event at a certain time, where I can then check in the client whether I want to show the notifications now. This is also not a very satisfactory solution, since it does not work offline and sends user information to the server.

Is there another possibility that I'm just overlooking?

Max
  • 1
  • My proposed solution in fact kind of works. However, there is one big problem I did not know about before. "[With push events, there is an additional requirement that you must display a notification before the promise you passed in has settled.](https://web.dev/push-notifications-handling-messages/#wait-until)" So it is not possible to send silent notifications and display them at an other time. Unfortunately, the whole logic has to be in the backend. – Max Apr 03 '23 at 12:20

0 Answers0