Search code examples
google-chromefirefoxcookiesweb-worker

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.

  • In Firefox, the request to get the PNGs contains the cookie for my site (domain A).

  • 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).

Which browser is behaving correctly, and can I do anything to make Chrome send the cookie for the current domain from within a webworker?

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.


Solution

  • 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:

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

    With regards to Chrome the Workers run in a separate they work for me and without seeing more code it's hard to answer. 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.