4

I am developing (and near to the release) of a Cordova App for iOS and Android.

I am trying to use cordova-plugin-ionic-webview in order to use the latest WebView engines.

I am able to use this plugin on iOS but on Android the App crashes on launch.

MY CONFIG.XML:

    <allow-navigation href="cordovaios://*" />
    <allow-navigation href="cordovaandroid://*" />
    <plugin name="cordova-plugin-ionic-webview" spec="^4.0.0">
        <variable name="ANDROID_SUPPORT_ANNOTATIONS_VERSION" value="27.+" />
    </plugin>
    <preference name="Hostname" value="my-backend-url-to-avoid-CORS.com" />
    <preference name="iosScheme" value="cordovaios" />
    <preference name="Scheme" value="cordovaandroid" />
    <preference name="ScrollEnabled" value="true" />
    <preference name="MixedContentMode" value="0" />
    <preference name="AllowBackForwardNavigationGestures" value="true" />
    <preference name="Allow3DTouchLinkPreview" value="false" />
    <preference name="WKSuspendInBackground" value="false" />
    <preference name="KeyboardAppearanceDark" value="false" />

LOGS:

5726-5770/mycertificate.enterprise D/SERVER: Handling local request: cordovaandroid://my-backend-url-to-avoid-CORS.com/static/js/10.601e7973.chunk.js

5726-5773/mycertificate.enterprise E/chromium: [ERROR:render_process_host_impl.cc(4070)] Terminating render process for bad Mojo message: Received bad user message: Origin is invalid

5726-5773/mycertificate.enterprise E/chromium: [ERROR:bad_message.cc(23)] Terminating renderer for bad IPC message, reason 123

NOTE:

This config works fine on iOS. On Android I can't use this plugin due to this Hostname/Origin issue.

Community
  • 1
  • 1
Gabe
  • 5,997
  • 5
  • 46
  • 92
  • 1
    Similar issue here (though in our case it doesn't crash): when we set the `Scheme`, the `Hostname` is ignored on Android. We use `cordova-plugin-ionic-webview` v4.0.1 and `cordova-android` v8.0.0 – rbarriuso Apr 24 '19 at 18:49

3 Answers3

3

That custom scheme does not appear to be supported (just try to find something alike that in the source code). It is also beyond my understanding, for what one even would even need to register a custom protocol handler, while never leaving that WebView? The usual purpose is: to open another application.

<preference name="Scheme" value="https" />
<allow-navigation href="https://my-backend-url-to-avoid-CORS.com/*"/>
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • 1
    The problem is that I also have to set the Hostname preference to "my-backend-url-to-avoid-CORS.com" meaning that requests to our backend will instead hit the webserver running on the device and serving the App, that's why I need a custom Origin. – Gabe Apr 24 '19 at 21:13
  • 1
    @GaSacchi the `Hostname` configuration should indicate local delivery... so that it can be told apart, even without a custom protocol handler. the only down-side is, that one cannot use that (merely local) host-name for anything else. it seems to be a web-server for local resources... which does not even seem as if would be able to avoid CORS, unless it would be fetching data elsewhere. – Martin Zeitler Apr 24 '19 at 21:15
  • avoiding CORS rather works alike [this](https://stackoverflow.com/a/54992590/549372); and one can add or change headers, too. – Martin Zeitler Apr 24 '19 at 21:23
  • Yes, the problem is though that the `Hostname` preference also changes the window.location object (eg. the Origin). This means asking 3rd party services that we use to whitelist the new Origin for CORS. Also we can't redirect requests through our servers in case of external vendors that we need to use. – Gabe Apr 25 '19 at 04:00
  • Then, this way is not valid to avoid CORS problems? – Hanzo Jul 09 '20 at 12:03
0

Unfortunately there is a lot of mismatching between the Cordova Android Platform version and plugins versions, which lead to some waste of time for nothing. Said so, for similar problemas I had like this I simply fixed them downgrading the version of Cordova or Android or the Plugin (or use the same version of android the plugin is using in their code example).

Cleriston
  • 750
  • 5
  • 11
  • Not if you focus on the plugin which is not working. Unfortunately I already had issues as simple as possible as Cordova changing the path of an output file and the plugin would stop working. My point of my answer is to get you to the right track of the problem. – Cleriston Apr 26 '19 at 05:27
0

In config.xml Try adding:

<allow-navigation href="*"/>

after:

<preference name="Scheme" value="https" />
<preference name="hostname" value="mobile.*.yourdomain.com" />
Anas
  • 711
  • 7
  • 24