Skip to content

Commit

Permalink
Add code to demonstrate getTags() and unregister().
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugdha Lakhani authored and mugdhalakhani committed Apr 25, 2019
1 parent d581ad6 commit a8fba43
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8fba43

Please sign in to comment.