First http requests does always not work over https and --release bundle


#1

We have some http get and posts in our ionic3 app which makes a HTTPS call to an external resource like https://smart.blabla.com

If we create a simple bundle with ionic cordova build android anything is fine and anything is working as expected.
If we create the release bundle with ionic cordova build android --release we have the problem that after every first open of the app on the first request to the cloud, the request is going wrong. No HTTP error or something like that. But the request is breaking client side.

This is the exception we can see if we do the same request native with XHR.

XMLHttpRequest.e.responseBlob.r.function.o.(anonymous function).P.(anonymous function).(anonymous function) 
u
t.scheduleTask
r.scheduleTask
r.scheduleMacroTask
(anonymous function)
r.(anonymous function)
(anonymous function)
InjectedScript._evaluateOn
InjectedScript._evaluateAndWrap
InjectedScript.evaluate

As mentioned before, with a not release bundle every thing is fine and we have the same error on emulator as on device.

We did see the same error before if the device is not ONLINE. in this case we have the same error. But this should not be the problem.

So we think there can be two reasons of this problem

  1. there are is any problem with the SSL certificate which android is not trusting on first time?
  2. the devices and emulator some times for a period are offline? And we must send in this case the request a second time? But this should also not the problem because in this case the problem should persist on using the app.

Some help? thx


Release build kills http request
HTTP GET over angular and also XMLHttpRequest throws strange error on cordova device
#2

I tried also to change confg.xml and add CSP meta tag in index.html like this:

<access origin="*" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src *; img-src 'self' data:; style-src 'self'; font-src 'self';">

Firstly it seems anything works great and it seems I resolved the issue using CSP but at the end after some tests I had the same error.


#3

So did this solve the problem? It’s bit unclear to understand now due to the last sentence…


#4

Maybe this is the reason https://stackoverflow.com/questions/44833534/http-requests-fails-only-while-releasing-android-apk/44838661#44838661


#5

Yes not sure why but using CSP is resolving my the issue.

Perhaps it is only a coincidence but I think using CSP is always better!