无法使GWT应用程序作为Chrome打包应用程序工作,可能是由于CSP [英] Can not make GWT application work as Chrome packaged app, probably due to CSP

查看:227
本文介绍了无法使GWT应用程序作为Chrome打包应用程序工作,可能是由于CSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续收到CSP错误:拒绝执行内联脚本,因为它违反了以下内容安全策略指令:script-src'self'



问题是可能是由于由GWT生成的包含内联JS的HTML文件。



UPD :更改为清单版本1有帮助,但这是一个临时工作,因为Chrome 21抱怨它不再被支持。


$ b UPD2: < add-linker name = xsiframe/> 也没有帮助

解决方案

GWT 2.5.1终于修复了问题,发布说明记录在这里:



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



并声明:



使用DirectInstallLinker构建的应用程序应该在内嵌s的页面中工作禁止使用限制(例如Chrome扩展程序)



这意味着现在可以使用DirectInstallLinker以满足清单版本2的新安全要求的方式链接Chrome打包应用程序也就是说,通过使用DirectInstallLinker将您的应用程序与选定为GWT版本的GWT 2.5.1关联起来,GWT不会将任何脚本元素内联到其生成的Javascript中,因此新的清单版本2要求不存在内联脚本不会被违反。



我发现SingleScriptLinker似乎也适用于我自己的应用程序;但是,问题7685警告不要使用SingleScriptLinker,因为This generate a $ doc.write在打包的应用程序中是禁用的。我自己使用DirectInstallLinker。



这里是DirectInstallLinker的Javadoc:



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



使用这个链接器,你可以在你的* .gwt.xml文件中包含以下内容:

 < define-linker name =dil class =com.google.gwt.core.linker.DirectInstallLinker/> 
< add-linker name =dil/>

(dil可以被您选择的任何东西取代,只要没有破折号或其他非法字符)。

您需要选择GWT 2.5.1作为您的GWT版本。如果您在过时的Eclipse版本(如Ganymede)中使用旧版本的GWT,则必须升级至少Helios,然后将您的项目导入到新的Eclipse环境中。可以在此处找到可用于最新三个Eclipse版本的Google Plugin for Eclipse的存档网址: https://developers.google.com/eclipse/docs/download



通过以上设置,您应该可以设置

 manifest_version:2 


并且不会因为GWT生成的内联Javascript而遇到任何错误。这应该允许您的Chrome网络应用程序为Chrome网上应用店所接受(现在需要为任何新应用程序显示版本2或用于展示应用程序的更新),只要没有其他问题。


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

The problem is probably due to HTML files generated by GWT which contain inline JS.

UPD: Changing to manifest version 1 helped, but this is a temporary workaroud, as Chrome 21 complains that it will no longer be supported.

UPD2: <add-linker name="xsiframe" /> does not help either

解决方案

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:

<define-linker name="dil" class="com.google.gwt.core.linker.DirectInstallLinker"/>
<add-linker name="dil" />

(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.

这篇关于无法使GWT应用程序作为Chrome打包应用程序工作,可能是由于CSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆