I am trying to understand why the chrome (and firefox) devtools network tab can see request/response cookies in an initial GET of a website, but node-fetch cannot.
For example, take stackoverflow.com. When I copy the initial GET with Google Chrome as a node fetch,
and try to print the request cookies, I don't get any. This is strange because per the image above, request cookies are provided by stack overflow in response to this GET.
let fetch = require('node-fetch')
fetch("https://stackoverflow.com/", {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;..."
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"pragma": "no-cache",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"cookie": "OptanonAlertBoxClosed=2021-04-07T22:42:43.384Z;..."
},
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors"
}).then(async (resp)=> {
console.log(resp.headers.get('set-cookie'))
});
(the console logs null
). I've deleted most of the cookies in this request for brevity, but you can see the OptanonAlertBoxClosed
in the copied fetch and in the request cookies in the image above.
Question
Why does Chrome devtools log request cookies for a GET to stackoverflow.com, but node-fetch does not?