Can't find serviceWorker in navigator anymore

↘锁芯ラ 提交于 2019-11-30 06:52:13

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/52299246/cant-find-serviceworker-in-navigator-anymore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!