Reputation: 41
ReferenceError: window is not defined
progressive web apps using at "add to home screen" not working. this is my services-workder.js
window.addEventListener('beforeinstallprompt', function(e) {
e.userChoice.then(function(choiceResult){
console.log(choiceResult.outcome);
if(choiceResult.outcome == 'dismissed'){
console.log('User cancelled home screen install');
}else{
console.log('User added to home screen');
}
});});
Upvotes: 0
Views: 2255
Reputation: 56034
That code is meant to run in the context of your web app's window
, not inside of your service worker's code.
So, move it to something like a <script>
tag inside of your HTML.
Upvotes: 1