Why am I seeing “Error - Only secure origins are allowed” for my service worker?

 ̄綄美尐妖づ 提交于 2019-12-02 18:33:57

Try using http://127.0.0.1:8080 for hosting locally instead of http://192.168.29.53:8080

From Service Worker FAQ:

Q: I get an error message about "Only secure origins are allowed". Why?

A: Service workers are only available to "secure origins" (HTTPS sites, basically) in line with a policy to prefer secure origins for powerful new features. However http://localhost is also considered a secure origin, so if you can, developing on localhost is an easy way to avoid this error.

You can also use the --unsafely-treat-insecure-origin-as-secure command-line flag. This flag must be combined with a --user-data-dir flag. For example:

$ ./chrome --user-data-dir=/tmp/foo --unsafely-treat-insecure-origin-as-secure=http://your.insecure.site

If you want to test on https://localhost with a self-signed certificate, do:

$ ./chrome --allow-insecure-localhost https://localhost

You might also find the --ignore-certificate-errors flag useful.

You can check for protocol before registering the service worker like this, location.protocol === 'https:' && serviceWorker.register('service-worker.js')

in chrome type chrome://flags

search "secure origin"

then click on Enabled, relaunch chrome.

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