cordova 10 has CORS issue with allowList

Viewed 5098

I'm developing a cordova application for Android , and after switch to cordova 10 , there is an error related to CORS problem, I remove the cordova-plugin-whitelist because of Deprecation Notice :

With the Allow List functionality now integrated into the core of Cordova Android (10.x and greater), this plugin is no longer required.

My config.xml file contains this line :

<access origin="*" />

Before switch to cordova 10 everything was fine, I'm googling these days but no result , tnx.

2 Answers

I just migrated my project from Cordova 9 to Cordova 10.1.1, now targeting Android 12 (API 31), along with Firebase for OAuth (per the docs).

The build went fine, but I started getting the err_connection_refused error trying to sign in via OAuth. The only thing required to resolve this was adding the preference name="AndroidInsecureFileModeEnabled" value="true" to the config.xml.

cordova-android 10.x moved to serving file via https:// protocol (WebAssetLoader) from the previous file:/// protocol. That means you need to change CORS settings on your server to allow the hostname under which your mobile app runs at. Default is https://localhost, but you could change the hostname using <preference name="hostname" value="localhost" /> setting (the protocol is not configurable.

If you don't change the hostname in Cordova, then you need to add https://localhost as allowed origin in your server configuration using the Access-Control-Allow-Origin header.

Related