Search code examples
cordovacorswhitelist

cordova 10 has CORS issue with allowList


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.


Solution

  • 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.