Can't find serviceWorker in navigator anymore

JavascriptGoogle ChromeService Worker

Javascript 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.

(MDN page, Chromium page).

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDieter InformationView Question on Stackoverflow
Solution 1 - JavascriptJosh LeeView Answer on Stackoverflow
Solution 2 - JavascriptSean256View Answer on Stackoverflow
Solution 3 - JavascriptmeydloView Answer on Stackoverflow
Solution 4 - JavascriptDaniya NiaziView Answer on Stackoverflow
Solution 5 - JavascriptMasoud MohajeriView Answer on Stackoverflow