Search code examples
javascriptreactjsbackground

Is there a way to keep my React JS PWA (Progressive Web App) running in background?


I coded a Chatting App and a Alarm clock App in React Js and they're working fine in foreground (while the apps are opened on screen). But I need a way to keep them running in the background to check for latest messages or to play the alarm sound. (Like clock app in phone or WhatsApp/Facebook)

Does anyone has solution?

I can't seem to find any solution, either by myself or Internet.


Solution

  • If you are targeting mobile devices, the best solution you have is to run a service worker, which can execute code in the background and show notifications. There are limits to the APIs available to a service worker, so playing a sound might not be possible.