CORS issue when testing on Android

Hello,

I recently updated our cordova plugins, and platform for android to satisfy Google’s Play Store API level 30 requirement.

As I was testing on Android I noticed that I get a CORS issue when hitting the /oauth/token endpoint.

The changes we made after changing the target api to 30 is as follows:

updated platform - cordova-android - 10.1.1
updated plugin - customurlscheme - git+https://github.com/Onegini/cordova-plugin-inappbrowser.git
added plugin - cordova-plugin-androidx-adapter - 1.1.3

Here is the error I get:

{
code: null
description: null
name: "Error"
original: "Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc. at Request.push../node_modules/auth0-js/dist/auth0.min.esm.js.Request.crossDomainError (http://192.168.1.80:8080/vendor.js:20552:63668) at XMLHttpRequest.xhr.onreadystatechange (http://192.168.1.80:8080/vendor.js:20552:65487)"
  crossDomain: true
  method: "POST"
  status: undefined
  url: "https://{OUR_DOMAIN}/oauth/token"
  message: "Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc."
  stack: "Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc. at Request.push../node_modules/auth0-js/dist/auth0.min.esm.js.Request.crossDomainError (http://192.168.1.80:8080/vendor.js:20552:63668)↵    at XMLHttpRequest.xhr.onreadystatechange (http://192.168.1.80:8080/vendor.js:20552:65487)"

}

We think this is happening to users on our Internal track build when we last deployed

1 Like

We have found a fix In our Config.xml we added these preferences in the platform android tag:

<preference name="hostname" value="localhost" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />

It appears that the CORS issue was related to a local development problem and the issue that our users face was related to an Error Connection problem with the app itself

2 Likes

Thanks for sharing it with the rest of community!