Explorar el Código

seviceworker.js: Added try / catch around reload call in doRegister to log in case of error

zinobias hace 2 años
padre
commit
d871a7867b
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. 5 1
      serviceWorker.js

+ 5 - 1
serviceWorker.js

@@ -55,7 +55,11 @@ async function doRegister() {
 		// f.e on first access.
 		registration.addEventListener("updatefound", () => {
 			console.log("Reloading the page to transfer control to the Service Worker.");
-			window.location.reload();
+			try {
+				window.location.reload();
+			} catch (err) {
+				console.log("Service Worker failed reloading the page. ERROR:" + err);
+			};
 		});
 		// If the registration is active, but it's not controlling the page, reload the page to have it take control
 		if (registration.active && !navigator.serviceWorker.controller) {