register-service-worker.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { register } from 'register-service-worker'
  2. // The ready(), registered(), cached(), updatefound() and updated()
  3. // events passes a ServiceWorkerRegistration instance in their arguments.
  4. // ServiceWorkerRegistration: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
  5. register(process.env.SERVICE_WORKER_FILE, {
  6. // The registrationOptions object will be passed as the second argument
  7. // to ServiceWorkerContainer.register()
  8. // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#Parameter
  9. // registrationOptions: { scope: './' },
  10. ready (/* registration */) {
  11. // console.log('Service worker is active.')
  12. },
  13. registered (/* registration */) {
  14. // console.log('Service worker has been registered.')
  15. },
  16. cached (/* registration */) {
  17. // console.log('Content has been cached for offline use.')
  18. },
  19. updatefound (/* registration */) {
  20. // console.log('New content is downloading.')
  21. },
  22. updated (/* registration */) {
  23. // console.log('New content is available; please refresh.')
  24. },
  25. offline () {
  26. // console.log('No internet connection found. App is running in offline mode.')
  27. },
  28. error (/* err */) {
  29. // console.error('Error during service worker registration:', err)
  30. }
  31. })