Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have an PWA application in MVC. I am currently developing the notification part where a notification toast will be prompted to users on certain cases. I have a service worker which will handle the 'push' event as below codes:
JavaScript
self.addEventListener('push', event => {
    var payload = event.data.text();
    var options = {
            body: payload,
            icon: '~/images/favicon.ico'
            //data : payload
        };

    event.waitUntil(self.registration.showNotification('Notification Testing', options));
});


When I run the application on browser(Chrome), the notification toast does pop out which means the 'push' event is able to handle the push successfully. But when I trigger the 'push' event again, the toast does not show up.

What I have tried:

1. Tried to click on the 'Push' button under Chrome Developer Tool and notification toast shows up.
2. Tried invoke the method in my controller for the second time and notification toast did not show up. Only first time does.
3. Have to clear the cache in Chrome history and clear site data under 'Application' tab in Chrome Developer Tool and reload the page only the notification toast will show up.
4. Have checked service worker and all is ok.
Posted
Updated 10-Sep-20 22:08pm

1 solution

I faced this issue.
The options param you missed this prop :
requireInteraction: true
Because the notification popup will auto close after 12s if requireInteraction prop is false.
So you should add this prop and two action buttons together (close & open) at bottom notification popup.
I'm finding a reason why the notification don't show after popup is closed automatic or user click to right arrow
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900