Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
## How to get the Service Worker on my Meteor App ?

1. Download sw.js and put it in the **root** of the /public folder.
2. Register your Service Worker to the client in your client :
`Meteor.startup(() => {
2. Register your Service Worker to the client in your client:

```
Meteor.startup(() => {
navigator.serviceWorker.register('/sw.js')
.then()
.catch(error => console.log('ServiceWorker registration failed: ', error));
});`
});
```

Service Workers are only available to **secure origins**. So be sure your server has https (localhost is considered as secure). And that the website you made request to are considered as secure. So your subdomain or your CDN must have HTTPS enabled.

## How it works
Expand Down
12 changes: 10 additions & 2 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ self.addEventListener('fetch', (event) => {
});
})
);

}

});

self.addEventListener('push', function (event) {
const data = event.data.json(); // Assumes JSON bodies
const options = {
body: data.body,
// icon: '/image/icon/192.png',
// badge: '/image/badge/192.png',
};
event.waitUntil(self.registration.showNotification(data.title, options));
});

function removeHash(element) {
Expand Down