Demo entry 6761858

javascript1

   

Submitted by anonymous on Oct 05, 2018 at 14:39
Language: JavaScript. Code size: 1.2 kB.

self.addEventListener('install', function (event) {
    // Perform install steps
});

self.addEventListener('fetch', event => {
    // intercepting fetch requests can happen here
});

self.addEventListener('push', (event) => {
    const promiseChain = self.registration.showNotification('Reversim roxx!!')
    event.waitUntil(promiseChain)
});

const APP_SERVER_KEY = 'XXX'

window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js')
        .then((registration) => {
            Notification.requestPermission((status) => {
                console.log('Notification permission status:', status);
            }).then(() => {
                const options = {
                    userVisibleOnly: true,
                    applicationServerKey: urlBase64ToUint8Array(APP_SERVER_KEY)
                }
                return registration.pushManager.subscribe(options)
            }).then((pushSubscription) => {
                // we got the pushSubscription object
            }
        }, (err) => {
                console.log('Service Worker registration failed', err)
            })
}));

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).