So I jumped on the train of service workers and push notifications. It seems to work well however I cannot figure out how to suppress notifications being displayed by the browser when the user is active in the tab, i.e. the tab is focused. Displaying notifications even while the user is working with the app would be bothering them too much -> they would just close them -> could lead to messages not being delivered if this exceeds some threshold.
This document mentions to add config to ngsw-config.json
, so I did put there:
"push": {
"showNotifications": true,
"backgroundOnly": true
}
However no matter what, messages are always displayed.
Should I just simply subscribe to messages, send them as data instead of notification
and display them manually?
constructor(swPush: SwPush) {
if (swPush.isEnabled) {
swPush.messages.subscribe(message => {
//display the message if tab is not active
});
}
}
If I do this, will that work in the background on mobile?
Edit: This approach of deciding in code whether to display message or not does work in Firefox but in Chrome I get 'The site has been updated in the background' message.
Frankly, I don't know how to move forward as I quite don't know what to do in SwPush.messages Observable to make Chrome happy. :(