简体   繁体   English

chrome为什么不从Webworker发送cookie?

[英]why does chrome not send cookies from a webworker?

I have a page on domain A which loads a webworker script from domain B. The webworker is fetching some PNGs from doman A's server. 我在域A上有一个页面,该页面从域B加载了Webworker脚本。Webworker正在从Doman A的服务器中获取一些PNG。

  • In Firefox, the request to get the PNGs contains the cookie for my site (domain A). 在Firefox中,获取PNG的请求包含我的网站(域A)的cookie。

  • In Chrome, it does not include the cookie for my site, and so fails because the request must be coming from a logged in user (which requires the session cookie to be sent in the request). 在Chrome中,它不包含我网站的cookie,因此失败,因为请求必须来自登录用户(这要求在请求中发送会话cookie)。

Which browser is behaving correctly, and can I do anything to make Chrome send the cookie for the current domain from within a webworker? 哪种浏览器运行正常,我可以做些什么使Chrome从Webworker中发送当前域的Cookie?

UPDATE: 更新:

I pulled all the files from domain B and hosted them on my server at domain A, so the webworker file is now on the same domain as the site itself, but Chrome still does not send the session cookie with the requests from the web worker. 我从域B中提取了所有文件,并将它们托管在域A的服务器上,因此webworker文件现在与网站本身位于同一域中,但是Chrome仍然不发送带有Web worker请求的会话cookie。

With regards to the first problem, it looks like the Firefox is incorrect, you shouldn't be able to instantiate a Worker on another domain to quote the spec : 关于第一个问题,看来Firefox是不正确的,您不应该能够实例化另一个域上的Worker来引用规范

"If the scheme component of worker URL is not "data", and the origin of worker URL is not the same as the origin specified by the incumbent settings object, then throw a SecurityError exception and abort these steps." “如果辅助URL的方案组件不是“数据”,并且辅助URL的来源与现有设置对象指定的来源不同,则抛出SecurityError异常并中止这些步骤。

With regards to Chrome the Workers run in a separate they work for me and without seeing more code it's hard to answer. 关于Chrome,这些Workers是为我单独工作的,并且他们看不到更多代码,因此很难回答。 But if you visit this demo and break before the postMessage to the worker set document.cookie='test=1' you will see that when the request goes out from the worker it is set. 但是,如果您访问此演示并在将postMessage发送到工作程序集document.cookie='test=1'之前中断,则您会看到,从工作程序发出的请求已被设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM