W3cubDocs

/Web APIs

Headers: getSetCookie() method

Baseline 2023
Newly available

Since ⁨September 2023⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

The getSetCookie() method of the Headers interface returns an array containing the values of all Set-Cookie headers associated with a response. This allows Headers objects to handle having multiple Set-Cookie headers, which wasn't possible prior to its implementation.

This method is intended for use on server environments (for example Node.js). Browsers block frontend JavaScript code from accessing the Set-Cookie header, as required by the Fetch spec, which defines Set-Cookie as a forbidden response-header name that must be filtered out from any response exposed to frontend code.

Syntax

getSetCookie()

Parameters

None.

Return value

An array of strings representing the values of all the different Set-Cookie headers associated with a response.

If no Set-Cookie headers are set, the method will return an empty array ([ ]).

Examples

As alluded to above, running code like the following on the client won't return any results — Set-Cookie is filtered out from Headers retrieved over the network.

fetch("https://example.com").then((response) => {
  console.log(response.headers.getSetCookie());
  // No header values returned
});

However, the following could be used to query multiple Set-Cookie values. This is much more useful on the server, but it would also work on the client.

const headers = new Headers({
  "Set-Cookie": "name1=value1",
});

headers.append("Set-Cookie", "name2=value2");

headers.getSetCookie();
// Returns ["name1=value1", "name2=value2"]

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
getSetCookie 113 113 112 99 17 113 112 76 17 23.0 113 17

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie