Monday, September 19, 2016

Use ios cordova to load/block external content url with whitelist

For ios cordova project, since Cordova 6.0.0, (Cordova iOs 4.0.0), the function of cordova whiteplist plugin is merged into cordova core library in the source file of CDVWhiteList.m and CDVIntentAndNavigationFilter.m, so the there is no need to explicitly add the whitelist plugin into the ios cordova project.

One breaking function is when setting an external url, like https://www.google.com in config.xml's content element as below, it will not work,

    <content src="httsp://www.google.com" />

The reason is the top level url is only allow to file:// url, and it has be explicitly allowed in order to load the url. To solve the issue, add the below line to allow navigate to any url
    <allow-navigation href="*" />


The whitelist related tags in config.xml are listed below:
1.<allow-navigation> allow root webview to navigate to a particular url

2. <allow-intent> allow opening an url in inappbrowser without giving permission to load cordova plugin on the url

3. <access> allow which url the javascrpit xhr reqeust can be made to it.

In addition, the index.html created with default cordova project also have CSP (content security policy), which may limit what is able to run on the cordova page, The below is a good tutorial for the related information.
http://go.microsoft.com/fwlink/?LinkID=617697



1 comment:

  1. Do you know that Anegis axaptais one of the best consulting companies you can work with?

    ReplyDelete