Windows 10 App :Host Defined Policy: Inline Script. Resource will be blocked.

I recently ported one of my java script projects to Windows store app and got the error as following

CSP14321: Resource violated directive ‘script-src ms-appx: ‘unsafe-eval’ blob:’ in Host Defined Policy: inline script, in ms-appx://13bdc914-5111-4c95-a5e6-82029c5105ec/index.html at line 21 column 12. Resource will be blocked.

If you have something like the following, it won’t work

<a href="javascript:void(0)" id="somelink" onclick="callMethod();">Link</a>

Since I was using jQuery in the project, I simply used jQuery to bind click event to the element

$("#somelink").click(function () {

and Voila, everything works but I had many pages which had this reference and I had to make this change to all pages. After some research I found that there is an alternate way which is much faster to change. By default ms-appx:/// protocol is used in store apps to fetch the content. For web apps specify a specific protocal ms-appx-web which is then used for the app. This can be done by changing start page from index.html to ms-appx-web:///index.html in package.appxmanifest. Also add highlighted rule in your package.appxmanifest (You will need to modify it in coding view and not the visual editor)

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="" xmlns:mp="" xmlns:uap="" IgnorableNamespaces="uap mp">
  <Identity Name="1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" Version="" Publisher="CN=User" />
  <mp:PhoneIdentity PhoneProductId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="" MaxVersionTested="" />
    <Resource Language="x-generate" />
    <Application Id="App" StartPage="ms-appx-web:///index.html">
      <uap:VisualElements DisplayName="MyApp" Description="My App Description" BackgroundColor="transparent" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
        <uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png">
        <uap:SplashScreen Image="images\splashscreen.png" />
        <uap:Rule Match="ms-appx-web:///" Type="include" WindowsRuntimeAccess="all" />
    <Capability Name="internetClient" />

Quick and easy..


Leave A Comment

Your email address will not be published.