mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	reload page when sw installed.
This commit is contained in:
		@@ -1,7 +1,17 @@
 | 
			
		||||
if ('serviceWorker' in navigator) {
 | 
			
		||||
  window.addEventListener('load', function () {
 | 
			
		||||
  window.addEventListener('DOMContentLoaded', function () {
 | 
			
		||||
    navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
 | 
			
		||||
      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 => {
 | 
			
		||||
        console.log('ServiceWorker registration update: ', res);
 | 
			
		||||
      });
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user