mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-20 04:30:17 +09:00
更新serviceworker逻辑
This commit is contained in:
parent
4b84fb328c
commit
eb7c7cdcb6
@ -7,6 +7,7 @@ self.addEventListener("activate", function (event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("install", function (event) {
|
self.addEventListener("install", function (event) {
|
||||||
|
self.skipWaiting(); // 立即启用新的版本
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CHATGPT_NEXT_WEB_CACHE).then(function (cache) {
|
caches.open(CHATGPT_NEXT_WEB_CACHE).then(function (cache) {
|
||||||
return cache.addAll([]);
|
return cache.addAll([]);
|
||||||
|
@ -2,8 +2,15 @@ if ('serviceWorker' in navigator) {
|
|||||||
window.addEventListener('load', function () {
|
window.addEventListener('load', function () {
|
||||||
navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
|
navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
|
||||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||||
|
registration.update().then(res => {
|
||||||
|
console.log('ServiceWorker registration update: ', res);
|
||||||
|
});
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
console.error('ServiceWorker registration failed: ', err);
|
console.error('ServiceWorker registration failed: ', err);
|
||||||
});
|
});
|
||||||
|
navigator.serviceWorker.addEventListener('controllerchange', function() {
|
||||||
|
console.log('ServiceWorker controllerchange ');
|
||||||
|
window.location.reload(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user