Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

39 lines (33 sloc) 1.02 KB
<!doctype html>
<html>
<head>
<title>installing service worker</title>
<script type="text/javascript">
//Register the service worker
if("serviceWorker" in navigator) {
navigator.serviceWorker.register("https://mweb-demos.appspot.com/amp-as-pwa/sw.js").then(function(reg){
console.log('ServiceWorker register with scope: ', reg.scope);
}).catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
});
}else{
console.log('SW is not supported');
}
//intercept beforeinstallprompt event and show the Add to Homescreen prompt
window.addEventListener('beforeinstallprompt', (event) => {
console.log('beforeinstallprompt event fired')
event.preventDefault();
event.prompt();
event.userChoice.then((choice) => {
if (choice.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
});
});
</script>
</head>
<body>
</body>
</html>
You can’t perform that action at this time.