Can't find serviceWorker in navigator anymore
JavascriptGoogle ChromeService WorkerJavascript Problem Overview
since the new update of Google Chrome (version 69.0.3497.92 (official build) (64-bit)) I can't find the serviceWorker service in the Navigator anymore. Actually I could register my Service Worker as follows but now I get an error that serviceWorker cannot be found in the navigator:
if('serviceWorker' in navigator) {
/*
*
* Register the Service Worker
*
* */
navigator.serviceWorker.register('sw.js').then(function(registration) {
console.log('Service Worker Registered');
});
} else console.log('Your browser does not support the Service-Worker!');
How can I now use the Service Worker again, or how can I get it to run again for all Chrome versions?
Javascript Solutions
Solution 1 - Javascript
Serve your page over HTTPS or use localhost
. Service workers require a Secure Context.
The value of window.isSecureContext
indicates whether [SecureContext]
features are visible or hidden. (This is true
on a file://
URL and the serviceWorker API will be visible, but it won't work, of course.)
Solution 2 - Javascript
If you are using a virtual host locally for a domain other than localhost, you can tell chrome to treat your custom domain as "secure".
In the addressbar: chrome://flags/#unsafely-treat-insecure-origin-as-secure
Then add your domain like http://my-local-dev-domain.test
Click enable and click the restart button.
Solution 3 - Javascript
Another reason might be running a browser in private-mode
Solution 4 - Javascript
Go to your vscode settings in the user>Extension option scroll down to live server config
set your host to localhost --ScreenShot Set host to local host
Now scroll down and uncheck use local IP option -- ScreenShot uncheck localIP
go to your Port json setting and set the port to 8080 --ScreenShot json setting set port to 8080 Go live and check console
Solution 5 - Javascript
insteade http://192.168.1.105:8080/ go to http://localhost:8080/ it worked for me