Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created September 23, 2022 15:37
Show Gist options
  • Save thangman22/8e60e10fa5a46f50291cf8c2a612e336 to your computer and use it in GitHub Desktop.
Save thangman22/8e60e10fa5a46f50291cf8c2a612e336 to your computer and use it in GitHub Desktop.
addEventListener('backgroundfetchclick', async (event) => {
const bgFetch = event.registration
if (bgFetch.result === 'success') {
const cache = await caches.open('postr-download')
const records = await cache.matchAll()
const cacheList = []
for (const record of records) {
const recordDate = new Date(record.headers.get('date'))
cacheList.push({
url: record.url,
date: recordDate.getTime() / 1000
})
}
clients.openWindow(cacheList.sort((a, b) => b.date - a.date)[0].url)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment