Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service workers on cordova app

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.

like image 876
Hoisel Avatar asked Oct 07 '16 16:10

Hoisel


People also ask

Is Cordova outdated 2021?

3. CORDOVA VS IONIC. Ionic is an open-source mobile toolkit for building cross-platform apps, and it's not Cordova-based anymore since May 2021.

Is Cordova still popular?

And nowadays, according to Statista, Cordova's popularity is decreasing. The number of software developers who used Apache Cordova in 2019–2021 fell from 29% to 16%.

Is Apache Cordova still supported?

Starting April 1, 2022, the App Center service will no longer accept calls from the Cordova SDK. While the services may continue to work for a short period of time afterward, we do not guarantee interaction of services or availability in the App Center portal.

Is Cordova hybrid or native?

With Apache Cordova framework build native-like applications targeted iOS and Android devices by accessing device's capabilities such as sensors, data, network status, etc. The application itself is implemented as a web page, by default a local file named index.


1 Answers

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.

like image 116
Roland Avatar answered Oct 08 '22 00:10

Roland