Skip to content

Instantly share code, notes, and snippets.

View indreklasn's full-sized avatar
👋

Trevor I. Lasn indreklasn

👋
View GitHub Profile
module.exports = {
"globDirectory": ".",
"globPatterns": [
"**/*.{js,html,json,css,lock}"
],
"swDest": "sw.js",
"swSrc": "src-sw.js"
};
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
console.log('Reading from src-sw.js');
workbox.precaching.precacheAndRoute([]);
if ('serviceWorker' in navigator) {
// attach event listener on page l aod
window.addEventListener('load', () => {
// register serviceWorker withthe [sw.js] file
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
module.exports = {
"globDirectory": ".",
"globPatterns": [
"**/*.{js,html,json,css,lock}"
],
"swDest": "sw.js"
};
Notification.requestPermission(result => {
if (result === 'granted') {
showNotification('So nice to have you here!', 'Hey there!')
}
});
function showNotification(title, message) {
if ('Notification' in window) {
navigator.serviceWorker.ready.then(registration => {
registration.showNotification(title, {
Notification.requestPermission(result => {
if (result === 'granted') {
if ('Notification' in window) {
navigator.serviceWorker.ready.then(registration => {
registration.showNotification('Vibration Sample', {
body: 'Buzz! Buzz!',
tag: 'vibration-sample'
});
});
Notification.requestPermission(result => {
if (result === 'granted') {
navigator.serviceWorker.ready.then(registration => {
registration.showNotification('Vibration Sample', {
body: 'Buzz! Buzz!',
tag: 'vibration-sample'
});
});
}
});
Notification.requestPermission(result => {
console.log(result)
if (result === 'granted') {
alert('thanks for giving me permissions')
}
});
self.addEventListener('fetch', e => {
console.log(caches)
e.respondWith(
caches.match(e.request).then(res => {
return res
})
)
})