[solved] Authenticated Request

After login to a page, I want to make a request to another URL on that site to get some json data. That json data is only available when logged in. In my legacy extension (JetPack based) I could just make the request and the users cookies were used. Now in the background script this doesn’t work anymore. I tried to add a “Cookie” header, but I can’t get that to work. It seems like I can’t get any header it into the request.

I’m doing this:

var headers = new Headers();
headers.append('Cookie', auth_cookie); // I get auth_cookie via the cookies API and it's correct
console.log(headers); // always "Headers { }", where is the content?
var request = new Request(info_url, {"headers": headers});
console.log("headers", request.headers); // also empty
fetch(request)
...

Inspecting the XHR request in the addon debug window also shows no sign of any header I try.

Is there a way to fetch data as the user?

Regards,
Florian Schulze

Tried setting credentials to true?

Thank you! I found withCredentials before, but missed the equivalent. I’m setting it to ‘same-origin’ and everything works now.

Regards,
Florian Schulze