Service Worker not working for Mobile Web (Chrome, Firefox, IE)

你。 提交于 2020-12-06 12:14:05

问题


I set up a service worker for a static web application that needs to work on mobile phones. I'm using react/webpack2 for this application.

Service Worker installs and works greatly when I open the application via desktop, but when I try to visit the application through mobile, it does not install. When SW finishes installing, it gives you an alert message ("onInstalled");

https://abo-deg.surge.sh (here is an example)

https://abo-deg.surge.sh/survey/background

https://github.com/strongharris/sample (sw.js located inside src, main entrypoint: src/index.js, webpack.config)

The alert message shows up via desktop, but not on mobile browsers. Am I missing something? Is there a different way to set up a service worker for mobile web applications? Any resources, or tips, or guesses would be greatly appreciated.


回答1:


I think the answer is pretty simple. Your server does not automatically transfer you to https://abo-deg.surge.sh when you type abo-deg.surge.sh on your mobile.

I was able to run it on Chrome Mobile by typing full URL with https://

Service worker API is available only for websites running over HTTPS, because

Having modified network requests wide open to man in the middle attacks would be really bad https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API

Please keep in mind, that your code will work only on these browsers, so don't expect it to work on iOS



来源:https://stackoverflow.com/questions/45024738/service-worker-not-working-for-mobile-web-chrome-firefox-ie

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