Service Worker不适用于移动Web(Chrome,Firefox,IE) [英] Service Worker not working for Mobile Web (Chrome, Firefox, IE)

查看:67
本文介绍了Service Worker不适用于移动Web(Chrome,Firefox,IE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为需要在手机上工作的静态Web应用程序设置了服务人员.我正在为此应用程序使用react/webpack2.

当我通过桌面打开应用程序时,Service Worker会安装并正常工作,但是当我尝试通过移动设备访问该应用程序时,它不会安装.SW完成安装后,会向您发出警报消息("onInstalled");

https://abo-deg.surge.sh (此处为示例)

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

https://github.com/strongharris/sample (位于src内的sw.js,主要入口点:src/index.js,webpack.config)

警报消息通过桌面显示,但不在移动浏览器上显示.我想念什么吗?是否有其他方法为移动Web应用程序设置服务工作者?任何资源,技巧或猜测都将不胜感激.

解决方案

我认为答案很简单.在手机上键入 abo-deg.surge.sh 时,服务器不会自动将您转移到 https://abo-deg.surge.sh .

我可以通过使用https://

键入完整的URL在Chrome Mobile上运行它

Service Worker API仅适用于通过HTTPS运行的网站,因为

在中间攻击中对人开放的修改过的网络请求确实很糟糕 https://developer.mozilla.org/zh-CN/docs/Web/API/Service_Worker_API

请记住,您的代码只能在这些浏览器上运行,所以不要希望它可以在iOS上运行

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.

解决方案

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

这篇关于Service Worker不适用于移动Web(Chrome,Firefox,IE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆