Authored by 郭成尧

es6->es5

const usePwa = location.protocol === 'https:';
const isHttps = location.protocol === 'https:';
const usePwa = isHttps;
window.addEventListener('load', function() {
if ('serviceWorker' in navigator) {
... ... @@ -14,15 +15,17 @@ window.addEventListener('load', function() {
console.log('SW registration failed: ', err);
});
} else {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
registration.unregister().then(result => {
console.log('SW unregisted: ', result);
}).catch(err => {
console.log('SW unregistration failed: ', err);
});
}
});
if (isHttps) {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
registration.unregister().then(result => {
console.log('SW unregisted: ', result);
}).catch(err => {
console.log('SW unregistration failed: ', err);
});
}
});
}
}
}
});
... ...
... ... @@ -84,7 +84,7 @@ self.addEventListener('install', function(event) {
// );
});
self.addEventListener('error', event => {
self.addEventListener('error', function(event) {
console.error('error', event);
// 上报错误信息
... ... @@ -96,7 +96,7 @@ self.addEventListener('error', event => {
// event.error.stack
});
self.addEventListener('unhandledrejection', event => {
self.addEventListener('unhandledrejection', function(event) {
console.error('unhandledrejection', event);
// 上报错误信息
... ...