Skip to content

Instantly share code, notes, and snippets.

@benstov
Forked from jeffposnick/index.html
Created December 16, 2019 14:26
Show Gist options
  • Save benstov/4ae9dd698ed690d437a4e276de2f859b to your computer and use it in GitHub Desktop.
Save benstov/4ae9dd698ed690d437a4e276de2f859b to your computer and use it in GitHub Desktop.
beforeinstallprompt demo
<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>
{
"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"
}
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