-
-
Save benstov/4ae9dd698ed690d437a4e276de2f859b to your computer and use it in GitHub Desktop.
beforeinstallprompt demo
This file contains 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
<html> | |
<head> | |
<title>Test</title> | |
<link rel="manifest" href="manifest.json"> | |
</head> | |
<body> | |
<p> | |
If the <code>beforeinstallprompt</code> event fires, there will be a button displayed allowing | |
you to use <code>prompt()</code> on the deferred event. | |
</p> | |
<button hidden>Show Prompt</button> | |
<script> | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('sw.js'); | |
window.addEventListener('beforeinstallprompt', event => { | |
event.preventDefault(); | |
var button = document.querySelector('button'); | |
button.removeAttribute('hidden'); | |
button.addEventListener('click', () => { | |
event.prompt(); | |
button.setAttribute('disabled', true); | |
}); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
This file contains 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
{ | |
"short_name": "PWA Test", | |
"name": "PWA Test", | |
"icons": [ | |
{ | |
"src": "https://raw.githubusercontent.com/jeffposnick/create-react-pwa/master/favicon.ico", | |
"sizes": "192x192", | |
"type": "image/png" | |
} | |
], | |
"start_url": "./", | |
"display": "standalone" | |
} |
This file contains 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('install', () => self.skipWaiting()); | |
self.addEventListener('activate', () => self.clients.claim()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment