mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-20 04:30:17 +09:00
reload page when sw installed.
This commit is contained in:
parent
ac470a6d07
commit
a765237441
@ -1,7 +1,17 @@
|
|||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', function () {
|
window.addEventListener('DOMContentLoaded', 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);
|
||||||
|
const sw = registration.installing || registration.waiting
|
||||||
|
if (sw) {
|
||||||
|
sw.onstatechange = function() {
|
||||||
|
if (sw.state === 'installed') {
|
||||||
|
// SW installed. Reload for SW intercept serving SW-enabled page.
|
||||||
|
console.log('ServiceWorker installed reload page');
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
registration.update().then(res => {
|
registration.update().then(res => {
|
||||||
console.log('ServiceWorker registration update: ', res);
|
console.log('ServiceWorker registration update: ', res);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user