web-push


How can I hide notifications my site is displaying if it is focused and brought to the foreground?


Context: I am building a progressive web apps that sends my users push notifications with service worker.
Is there a way to ensure that if the user browses to my site while notifications are currently showing that the notifications are hidden?
I want to avoid the situation where they navigated to my site and the notifications are still displaying, now stale.
Yes, from the document you can clear all currently showing notifications like this:
// From a document.
navigator.serviceWorker.ready.then(registration => {
registration.getNotifications().then(notifications =>
notifications.forEach(notification => notification.close()));
});
You could choose to simply run this code every time a page loads to solve your case, or you could additionally add a focus event listener to the document that runs this code to ensure it is applied every time your site is brought into focus.

Related Links

My Pushpad Sender does not send any more notifications
Pushpad or Web push notification how to custom dialog message
What is VAPID and why is it useful?
How can I test pushsubscriptionchange event-handling code?
How should I handle the pushsubscriptionchange event?
How can I hide notifications my site is displaying if it is focused and brought to the foreground?
Do I need to show a notification in response to a push notification if my site is foreground and focused?
Getting customized message from GCM using Web push notifications
Firefox Push API - AbortError: Error retrieving push subscription

Categories

HOME
qt
android-studio
class
keyboard
weblogic12c
key
subdomain
ews
risk-management
odata
vsts-build
tabs
cryptography
ontology
firebase-dynamic-links
save
phpseclib
lc3
getopenfilename
google-awareness
sql-injection
distributed-computing
corona
async-await
clr
android-custom-view
opam
conda
amazon-sns
animated-gif
cellular-network
window-managers
clipboard
android-cardview
onchange
oracleforms
guice
es6-modules
gnu-classpath
xvfb
widestring
swfupload
grails-spring-security
httphandler
doctrine-extensions
jshint
axis
rightnow-crm
sony-future-lab-n
maven-jaxb2-plugin
webvtt
scala-collections
kendo-treeview
prefetch
gawk
yargs
deviare
bigdecimal
livecycle
django-testing
always-on-top
xcode8-beta4
fiber
univocity
godeps
smart-tv
libz
modern.ie
cache-manifest
mathematical-expressions
jcheckbox
otl
maven-central
android-2.3-gingerbread
accessory
jini
ivalueconverter
libxml-js
apportable
jquery-lazyload
asp.net-mvc-3-areas
reentrancy
story
audiotoolbox
image-formats
pageheap
fitch-proofs
uploading
sql-parametrized-query
fragment-identifier
printqueue
eaccelerator
tessellation
pinax
iphone-sdk-4.3
rational-unified-process
fxruby

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App