Created
September 23, 2022 15:45
-
-
Save thangman22/1c5cd8f5d23ea9d267be5771194cb498 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
const swReg = await navigator.serviceWorker.ready | |
const bgFetchRegistration = await swReg.backgroundFetch.fetch('postr-download', ['image.png'], { | |
title: 'Postr.me is capturing', | |
icons: [{ | |
sizes: '512x512', | |
src: '/assets/img/icon-512.png', | |
type: 'image/png' | |
}], | |
downloadTotal: 60 * 1024 * 1024 | |
}) | |
bgFetchRegistration.addEventListener('progress', event => { | |
fetchProgress = event.currentTarget; | |
progressStatus.innerHTML = `Progress: downloaded ${bytesToSize( | |
fetchProgress.downloaded | |
)} from ${bytesToSize(fetchProgress.downloadTotal)} (${Math.round( | |
(fetchProgress.downloaded * 100) / fetchProgress.downloadTotal | |
)}%)`; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment