Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created September 23, 2022 15:24
Show Gist options
  • Save thangman22/f60798c65704de75bc48ddf5e1e3bd65 to your computer and use it in GitHub Desktop.
Save thangman22/f60798c65704de75bc48ddf5e1e3bd65 to your computer and use it in GitHub Desktop.
addEventListener('backgroundfetchsuccess', event => {
event.updateUI({
title: 'Postr.me capturing sucessful',
icons: [{
sizes: '512x512',
src: '/assets/img/icon-512.png',
type: 'image/png'
}]
})
event.waitUntil(
(async () => {
try {
const cache = await caches.open(event.registration.id)
const records = await event.registration.matchAll()
const promises = records.map(async record => {
const response = await record.responseReady
await cache.put(record.request, response)
})
await Promise.all(promises)
} catch (err) {
console.error(err)
}
})()
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment