Newer
Older
Sébastien DA ROCHA
committed
/* eslint-disable no-console */
import { register } from 'register-service-worker';
Sébastien DA ROCHA
committed
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready () {
console.log(
'App is being served from cache by a service worker.\n' +
'For more details, visit https://goo.gl/AFskqB'
Sébastien DA ROCHA
committed
},
registered (registration) {
//console.log('Service worker has been registered.')
console.log(
'Service worker has been registered and now polling for updates.'
registration.update();
}, 10000); // every 10 seconds
Sébastien DA ROCHA
committed
},
cached () {
console.log('Content has been cached for offline use.');
Sébastien DA ROCHA
committed
},
updatefound () {
console.log('New content is downloading.');
Sébastien DA ROCHA
committed
},
if (!navigator.webdriver) {
alert('Une nouvelle version de l\'application est disponible, l\'application va se recharger');
console.log('New content is available; please refresh.');
//
if (!registration || !registration.waiting) {
return;
}
// Send message to SW to skip the waiting and activate the new SW
registration.waiting.postMessage({ type: 'SKIP_WAITING' });
//window.location.reload(true);
} else {
console.log('Execution dans un navigateur controlé par un agent automatisé, la mise à jour n\'est pas appliqué pendant le test.');
Sébastien DA ROCHA
committed
},
offline () {
console.log('No internet connection found. App is running in offline mode.');
Sébastien DA ROCHA
committed
},
error (error) {
console.error('Error during service worker registration:', error);
Sébastien DA ROCHA
committed
}