经过数周的工作,我现在终于准备好部署我的应用程序,以发现流星似乎没有在iframe中运行.当顶级窗口和iframe在同一个域上运行时,它可以正常工作,但在域不同时则不行.我在Chrome上遇到的错误是:
Uncaught SecurityError: Access to 'sessionStorage' is denied for this document.
在那个错误之后,Meteor的初始化似乎停止了,甚至连Meteor
自身都没有被定义.
经过一番挖掘,我找到了这个参考和解释:http://www.w3.org/TR/webstorage/#user-tracking :" 阻止第三方存储 用户代理可能会限制对localStorage对象的访问,因为脚本来自于浏览上下文的顶级文档的域,例如拒绝访问在iframe中运行的其他域中的页面的API."
问题不是我的应用程序特有的.您可以使用流星图库中的任何演示应用程序并尝试将它们嵌入到具有iframe的另一个页面中,您将看到我的意思.
有没有办法解决?
编辑2014-01-07: 我已经尝试包装了一些在try-catch块中抛出异常的地方,但是给人的印象是,这太过于使流星瘫痪,以至于由于其他原因而无法正确初始化.
我无法重现您遇到的具体问题,但以下是为了使其正常工作所遵循的步骤.也许我们可以从那里解构它并弄清楚错误是什么.
我创建了一个空白应用程序
流星创建testapp
然后我添加了浏览器策略模块:
meteor添加浏览器策略
然后我编辑了testapp.js以使其使用Session:
if (Meteor.isClient) { Template.hello.greeting = function () { return Session.get( 'welcome_text' ); }; Template.hello.events({ 'click input' : function () { // template data, if any, is available in 'this' if (typeof console !== 'undefined') console.log("You pressed the button"); Session.set( 'welcome_text', 'Hello: ' + Math.random() ); } }); } if (Meteor.isServer) { BrowserPolicy.framing.allowAll(); Meteor.startup(function () { // code to run on server at startup }); }
我创建了两个nginx虚拟主机:
server { listen 80; server_name test1.com; location / { proxy_pass http://127.0.0.1:3000/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } server { listen 80; server_name test2.com; location / { alias /websites/test2.com } }
test1是meteor app,test2是iframe.
对于test2,我创建了/websites/test2/index.html:
<iframe src="http://test1.com">
然后我将test1.com和test2.com添加到我的hosts文件并启动了meteor应用程序.
我在浏览器上访问了http://test2.com,一切都按预期工作.看起来你或多或少尝试过这些步骤,但是你的应用程序或服务器堆栈可能有其他组件干扰了浏览器策略.
我首先更新您的问题,以包含流星应用程序的请求和响应标头.你的流星应用程序是否在代理服务器后面运行?