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
| button.addEventListener('click', async () => { | |
| deferredPrompt.prompt(); | |
| const { outcome } = await deferredPrompt.userChoice; | |
| if (outcome === 'accepted') button.setAttribute('hidden', '); | |
| // Send an analytics event for either dismissed or accepted! | |
| }); |
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
| button.addEventListener('click', async () => { | |
| deferredPrompt.prompt(); | |
| // ... | |
| }); |
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
| button.addEventListener('click', async () => { | |
| deferredPrompt.prompt(); | |
| // ... | |
| }); |
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
| let deferredPrompt; | |
| window.addEventListener('beforeinstallprompt', e => { | |
| e.preventDefault(); // prevent mini info bar popping up | |
| deferredPrompt = e; | |
| // show install button somewhere! | |
| }); |
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
| navigator.serviceWorker.addEventListener('controllerchange', () => { | |
| window.location.reload(); | |
| }); |
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('message', (event) => { | |
| if (event.data && event.data.type === 'SKIP_WAITING') { | |
| self.skipWaiting(); | |
| } | |
| }); |
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
| button.addEventListener('click', () => { | |
| newWorker.postMessage({ type: 'SKIP_WAITING' }); | |
| }); |
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
| const reg = await navigator.serviceWorker.getRegistration(); | |
| reg.addEventListener('updatefound', () => { | |
| const newWorker = reg.installing; | |
| newWorker.addEventListener('statechange', () => { | |
| if (newWorker.state === 'installed') { | |
| // Update available! Show an install button | |
| } | |
| }); | |
| }); |
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
| const reg = await navigator.serviceWorker.getRegistration(); | |
| reg.addEventListener('updatefound', () => { | |
| // ... | |
| }); |
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(fetch, event => { | |
| // ready to handle requests! | |
| }); |