Skip to content

Commit

Permalink
feat(workbox): expose registration as window.$sw
Browse files Browse the repository at this point in the history
Also better error handeling when registration failed
  • Loading branch information
Pooya Parsa committed Nov 16, 2017
1 parent 6679d73 commit a5ddf59
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/workbox/templates/sw.plugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
window.onNuxtReady(() => {
if (!('serviceWorker' in navigator)) {
console.warn('serviceWorker is not supported')
console.warn('Service workers are not supported.')
return
}

navigator.serviceWorker.register('<%= options.swURL %>', {
scope: '<%= options.swScope %>'
})
}).then(function(registration) {
window.$sw = registration
}).catch(function(error) {
console.error('Service worker registration failed:', error);
});
})

0 comments on commit a5ddf59

Please sign in to comment.