Created
September 23, 2022 15:37
-
-
Save thangman22/8e60e10fa5a46f50291cf8c2a612e336 to your computer and use it in GitHub Desktop.
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
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