Since June 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
* Some parts of this feature may have varying levels of support.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Service Workers.
The get() method of the CookieStore interface returns a Promise that resolves to a single cookie matching the given name or options object. The method will return the first cookie that matches.
get(name) get(options)
This method requires one of the following:
name OptionalA string with the name of a cookie.
Or
options OptionalAn object containing:
Note: The url option enables the modification of a cookie scoped under a particular URL. Service workers can obtain cookies that would be sent to any URL under their scope. From a document you may only obtain the cookies at the current URL, so the only valid URL in a document context is the document's URL.
A Promise that resolves with an object representing the first cookie matching the submitted name or options, or null if there is no matching cookie.
The object returned for a match contains the following properties:
domainA string containing the domain of the cookie.
expiresA timestamp, given as Unix time in milliseconds, containing the expiration date of the cookie.
nameA string containing the name of the cookie.
partitionedA boolean indicating whether the cookie is a partitioned cookie (true) or not (false). See Cookies Having Independent Partitioned State (CHIPS) for more information.
pathA string containing the path of the cookie.
sameSiteOne of the following SameSite values: "strict", "lax", or "none".
secureA boolean value indicating whether the cookie is to be used in secure contexts only (true) or not (false).
valueA string containing the value of the cookie.
SecurityError DOMException
Thrown if the origin does not serialize to a URL.
TypeErrorThrown if:
options parameter is an empty object.url option is specified but does not match the URL of the current window.url option is specified, but does not match the origin of the worker.name or options fails.This example shows how to get a particular cookie by name.
The code first creates a cookie named "cookie1" using CookieStore.set(), logging any errors to the console. It then waits on get() to retrieve information about that same cookie. If the returned promise resolves with an object we log the cookie: otherwise we log that no matching cookie was found.
async function cookieTest() {
// Set test cookie
try {
await cookieStore.set("cookie1", "cookie1-value");
} catch (error) {
console.log(`Error setting cookie1: ${error}`);
}
// Get cookie, specifying name
const cookie = await cookieStore.get("cookie1");
if (cookie) {
console.log(cookie);
} else {
console.log("cookie1: Cookie not found");
}
}
cookieTest();
| Specification |
|---|
| Cookie Store API> # dom-cookiestore-get> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
get |
87 | 87 | 140 | 73 | 18.4 | 87 | 140 | 62 | 18.4 | 14.0 | 87 | 18.4 |
domain_return_property |
87 | 87 | No | 73 | No | 87 | No | 62 | No | 14.0 | 87 | No |
expires_return_property |
87 | 87 | No | 73 | No | 87 | No | 62 | No | 14.0 | 87 | No |
name_return_property |
87 | 87 | 140 | 73 | 18.4 | 87 | 140 | 62 | 18.4 | 14.0 | 87 | 18.4 |
partitioned_return_property |
114 | 114 | No | 100 | No | 114 | No | 76 | No | 23.0 | 114 | No |
path_return_property |
87 | 87 | No | 73 | No | 87 | No | 62 | No | 14.0 | 87 | No |
sameSite_return_property |
87 | 87 | No | 73 | No | 87 | No | 62 | No | 14.0 | 87 | No |
secure_return_property |
87 | 87 | No | 73 | No | 87 | No | 62 | No | 14.0 | 87 | No |
value_return_property |
87 | 87 | 140 | 73 | 18.4 | 87 | 140 | 62 | 18.4 | 14.0 | 87 | 18.4 |
© 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/CookieStore/get