Can not make GWT application work as Chrome packaged app, probably due to CSP

前端 未结 4 918
北恋
北恋 2020-12-31 18:23

Keep getting CSP errors: \"Refused to execute inline script because it violates the following Content Security Policy directive: \"script-src \'self\'\"

The problem

4条回答
  •  一生所求
    2020-12-31 18:49

    GWT 2.5.1 has finally fixed this problem. The release notes documenting this are here:

    https://developers.google.com/web-toolkit/release-notes#Release_Notes_2_5_1

    and they state that:

    "Apps built with DirectInstallLinker should work in a page where inline scripts are forbidden (e.g. a Chrome extension)"

    This means that it is now possible to use DirectInstallLinker to link your Chrome packaged app in a manner that satisfies the new security requirements of manifest version 2 regarding inline scripts. That is, by using DirectInstallLinker to link your app with GWT 2.5.1 selected as your GWT version, GWT will not place any script elements inline in its generated Javascript, and thus the new manifest version 2 requirement that there be no inline scripts will not be violated.

    I have found that SingleScriptLinker also seems to work for my own app; however, Issue 7685 warns against using the SingleScriptLinker because "This generates a $doc.write line which is forbidden in packaged apps." I am using DirectInstallLinker myself.

    Here is the Javadoc for DirectInstallLinker:

    http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/gwt/core/linker/DirectInstallLinker.html

    To use this linker, you can include the following in your *.gwt.xml file:

    
    
    

    (dil can be replaced by anything you choose, so long as there are no dashes or other illegal characters).

    You will need to select GWT 2.5.1 as your version of GWT. If you're using an older version of GWT in an out-of-date version of Eclipse such as Ganymede (as I was), you'll have to upgrade to at least Helios and then import your project to your new Eclipse environment. The archive URLs for the Google Plugin for Eclipse that can be used for the latest three Eclipse versions can be found here:

    https://developers.google.com/eclipse/docs/download

    With the above in place, you should be able to set

    "manifest_version": 2
    

    in your manifest.json file and not experience any errors due to GWT-generated inline Javascript. This should allow your Chrome Web app to be acceptable to the Chrome Web Store (which now requires manifest version 2 for any new apps or for updates to present apps), so long as there are no other issues.

提交回复
热议问题