Service workers on cordova app

2019-04-09 02:20发布

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条回答
乱世女痞
2楼-- · 2019-04-09 03:22

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.

查看更多
登录 后发表回答