How do I use window.fetch() with httpOnly cookies or basic auth

Damian Senn picture Damian Senn · May 3, 2015 · Viewed 7.6k times · Source

I'm playing around with window.fetch() in Firefox and Chrome. For some reasons, fetch() doesn't send any cookies. Now that wouldn't be a problem, as I can send them using

fetch('/something', { headers: { Cookie: document.cookie } })

But this won't work for httpOnly cookies.

Answer

Damian Senn picture Damian Senn · May 3, 2015

Okay, I found out after reading on the Mozilla Developer Network a bit more and trying out the credentials option.

Looks like the credentials option is what I should have looked for.

fetch('/something', { credentials: 'same-origin' }) // or 'include'

Will send the cookies.