Accessing local network with Cordova UWP app

478 Views Asked by At

I have a cordova app (SPA) and need to make an XmlHttpRequest to a local network resource.

If the app is in remote mode, I am not able/allowed to define the necessary privateNetworkClientServer capability (the app was actually rejected in the Windows Store because I defined this capability while remote mode was enabled). Without privateNetworkClientServer XmlHttpRequests to the local network do not work.

If the app is in local mode, I can define the necessary privateNetworkClientServer capability but I am also getting a lot of errors/warning:

CSP14312: Resource violated directive 'script-src ms-appx: data: 'unsafe-eval'' in Host Defined Policy: inline script. Resource will be blocked

This is probably because I am using jQuery to dynamically create/update the app contents, like $("#myelement").html(...) ?

So I am kind of stuck here. In both modes I am facing issues.

Is there any way to make a XmlHttpRequest to a local network resource without defining the privateNetworkClientServer capability? Is there any other way I should create the single page app, which is compatible with local mode?

1

There are 1 best solutions below

3
On

It should be the Content-Security-Policy that caused this issue, see the connect-src document,

The HTTP Content-Security-Policy (CSP) connect-src directive restricts the URLs which can be loaded using script interfaces.

You can try to add your local network URL to the connect-src resource directive in your index.html file's first meta Content-Security-Policy's content. As the following code, you can replace YOUR NETWORK URL with your URL.

 <meta http-equiv="Content-Security-Policy" content="default-src connect-src YOUR NETWORK URL  'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">