From a8fba436b9fa7ebdf3199f627dd15c7bbcc6673e Mon Sep 17 00:00:00 2001 From: Mugdha Lakhani Date: Wed, 17 Apr 2019 13:09:33 +0100 Subject: [PATCH] Add code to demonstrate getTags() and unregister(). --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 10d296f..e5b42bf 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,27 @@ self.addEventListener('periodicsync', event => { }); ``` +## Checking if a periodic sync task with a given tag is registered +```javascript +// index.html + +navigator.serviceWorker.ready.then(registration => { + registration.periodicSync.getTags().then(tags => { + if (tags.includes('get-latest-news')) + skipDownloadingLatestNewsOnPageLoad(); + }); +}); +``` + +## Removing a periodic sync when the user signs out +```javascript +// index.html + +navigator.serviceWorker.ready.then(registration => { + registration.periodicSync.unregister('get-latest-news'); +}); +``` + # Security and Privacy One-shot Background Sync allows the web page’s logic to live a little longer (service worker