Erik Simmler

Internaut, software developer and irregular rambler

Fetch() Doesn't Send Cookies By Default

Fetch is a lovely little api for making ajax requests. I’ve been using the github/fetch polyfill in lieu of full browser support, but with a recent chrome update all requests were being sent without cookies. At first it seemed to be a strangely obvious glitch in Chrome’s implementation, but the behavior turns out to be according to the spec.

I think it’s an odd default, but I’m sure they had their reasons. The difficulty comes from the fact that the polyfill can’t effectively mimic this behavior. Setting the credentials option to 'include' will cause fetch to add the appropriate cookie headers.

fetch(url, {
  credentials: "include",

In my case all requests go through a central wrapper, so it’s no big deal to add this as the default.

Reference: Fetch - Living Standard | HTML5 Rocks - Introduction to fetch()