Headers: getSetCookie() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2023.

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

js
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.

js
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.

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

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

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

Specifications

Specification
Fetch
# dom-headers-getsetcookie

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
getSetCookie
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
footnote Full support
Edge – Full support
Edge 113 (Release date: 2023-05-05)
footnote Full support
Firefox – Full support
Firefox 112 (Release date: 2023-04-11)
footnote Full support
Opera – Full support
Opera 99 (Release date: 2023-05-16)
footnote Full support
Safari – Full support
Safari 17 (Release date: 2023-09-18)
footnote Full support
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 112 (Release date: 2023-04-11)
footnote Full support
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
footnote Full support
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
footnote Full support
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
footnote Full support
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.35 (Release date: 2023-07-05)
footnote Full support
Node.js – Full support
Node.js 19.7 (Release date: 2023-02-21)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also