Service workers on cordova app

六眼飞鱼酱① 提交于 2019-12-13 11:45:06

问题


Can i use service workers inside hybrids apps(ionic 1/cordova) running on android devices? I'm getting some errors when trying to install a service worker on ionic app running on android device, because android uses file protocol to serve files and service-workers require files to be served by HTTPS protocol or http(only for localhost):

Error during service worker registration: DOMException: Failed to register a ServiceWorker: The URL protocol of the current origin ('file://') is not supported.

It's not a traditional progressive web application running on mobile browser, but instead on android device (webview + cordova).

I need achieve that to leverage my app with cache strategies(using sw-precache e sw-toolbox from google) on my api calls.


回答1:


Actually, according to caniuse, it is supported. The issue is with the protocol used.

If you read on Service Workers, you will see in prerequisites that in production you are required to use HTTPS.

Using Crosswalk might help though, take a look at XWALK-5919.



来源:https://stackoverflow.com/questions/39921733/service-workers-on-cordova-app

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