无法使GWT应用程序作为Chrome打包应用程序工作,可能是由于CSP

Ale*_*sky 8 gwt google-chrome-extension content-security-policy

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

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

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

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

Car*_*arl 9

GWT 2.5.1终于解决了这个问题.发布说明记录了这一点:

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

他们说:

"使用DirectInstallLinker构建的应用程序应该在禁止内联脚本的页面中工作(例如Chrome扩展程序)"

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

我发现SingleScriptLinker似乎也适用于我自己的应用程序; 但是,问题7685警告不要使用SingleScriptLinker,因为"这会生成一个$ doc.write行,在打包的应用程序中是禁止的." 我自己使用DirectInstallLinker.

这是DirectInstallLinker的Javadoc:

http://google-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" />
Run Code Online (Sandbox Code Playgroud)

(只要没有破折号或其他非法字符,你可以用你选择的任何东西替换).

您需要选择GWT 2.5.1作为您的GWT版本.如果你在一个过时的Eclipse版本中使用旧版本的GWT,比如Ganymede(就像我一样),你必须升级到至少Helios,然后将你的项目导入新的Eclipse环境.可以在此处找到可用于最新三个Eclipse版本的Google Plugin for Eclipse的归档URL:

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

有了上述,你应该能够设置

"manifest_version": 2
Run Code Online (Sandbox Code Playgroud)

在您的manifest.json文件中,由于GWT生成的内联Javascript,不会遇到任何错误.这应该允许您的Chrome网络应用程序被Chrome网上应用店(现在需要任何新应用的清单版本2或现有应用的更新)接受,只要没有其他问题.


Tho*_*yer 5

编辑:报告了新的GWT错误:http://code.google.com/p/google-web-toolkit/issues/detail?id = 7685,另请参阅http://gwt-code-reviews.appspot.com/1838803 /这与此错误有关

换句话说,看起来,当修复时,你只需要使用DirectInstallLinker(<add-linker name='direct_install'/>).

与此同时,IIUC,你必须扩展DirectInstallLinker和:

  • 覆盖getJsInstallLocation以返回installLocaltionIframe.js没有该$wnd部分的副本
  • 覆盖getModulePrefix以预先var $wnd = $wnd || window.parent;生成的内容super.getModulePrefix

我不知道CSP足以给出完整的答案,但xsiframe链接器是"可自定义的":创建一个扩展com.google.gwt.core.linker.CrossSiteIframeLinker和覆盖适当方法的类,然后使用<define-linker><add-linker>你的*.gwt.xml.

例如,getJsInstallLocation默认为,com/google/gwt/core/ext/linker/impl/installLocationIframe.js但有一个com/google/gwt/core/ext/linker/impl/installLocationMainWindows.js替代实现.

同样(可能更重要的是),getJsInstallScript默认为,com/google/gwt/core/ext/linker/impl/installScriptEarlyDownload.js但也有一个com/google/gwt/core/ext/linker/impl/installScriptDirect.js替代实现.

http://code.google.com/p/google-web-toolkit/source/browse/trunk/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java#204,HTTP:/ /code.google.com/p/google-web-toolkit/source/browse/trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/http://code.google. COM/p /谷歌web的工具包/源/浏览/中继/用户/ SRC/COM /谷歌/ GWT /型芯/ Core.gwt.xml