Last active
August 29, 2015 14:26
-
-
Save lholmquist/43bde013f7782809831c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X PUT SOME_REALLY_LONG_ENDPOINT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<link rel="stylesheet" href=""> | |
</head> | |
<body> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js | |
navigator.serviceWorker.register('./service-worker.js').then(function (serivceWorkerRegistration) { | |
console.log('registered service worker, YAY'); | |
console.log(serivceWorkerRegistration); | |
serivceWorkerRegistration.pushManager.subscribe().then(function (pushSubscription) { | |
// you want to use pushSubscription.endpoint for the sending | |
console.log(pushSubscription); | |
}).catch(function (err) { | |
console.log(err); | |
}); | |
}).catch(function (err) { | |
console.log(err); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('push', function (evt) { | |
console.log(evt); | |
console.log('Received a push message', event); | |
// THis didn't really work | |
// var title = 'Yay a message.'; | |
// var body = 'We have received a push message.'; | |
// var icon = '/images/icon-192x192.png'; | |
// var tag = 'simple-push-demo-notification-tag'; | |
// event.waitUntil( | |
// self.registration.showNotification(title, { | |
// body: body, | |
// icon: icon, | |
// tag: tag | |
// }) | |
// ); | |
}); | |
// The SW will be shutdown when not in use to save memory, | |
// be aware that any global state is likely to disappear | |
console.log("SW startup"); | |
self.addEventListener('install', function(event) { | |
console.log("SW installed"); | |
alert('SW Instaled'); | |
}); | |
self.addEventListener('activate', function(event) { | |
console.log("SW activated"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment