Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created September 23, 2022 15:45
Show Gist options
  • Save thangman22/1c5cd8f5d23ea9d267be5771194cb498 to your computer and use it in GitHub Desktop.
Save thangman22/1c5cd8f5d23ea9d267be5771194cb498 to your computer and use it in GitHub Desktop.
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