GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

cookies.getAll()

The getAll() method of the cookies API retrieves all cookies from a cookie store that match the details provided.

The **`getAll()`** method of the cookies API retrieves all cookies from a cookie store that match the details provided.

To use this method, an extension must have the `"cookies"` permission and relevant host permissions. See [`cookie` permissions](/docs/Mozilla/Add-ons/WebExtensions/API/cookies#permissions) for more details.

This is an asynchronous function that returns a [`Promise`](/docs/Web/JavaScript/Reference/Global_Objects/Promise).

## Syntax

```js-nolint
let getting = browser.cookies.getAll(
details // object
)
```

### Parameters

- `details`
- : An `object` containing details that are used to match cookies to retrieve. Included properties are as follows (see [Cookie type](/docs/Mozilla/Add-ons/WebExtensions/API/cookies/Cookie#type) for more information on these):
- `domain`
- : A `string` representing a domain that cookies must be associated with (they can be associated either with this exact domain or one of its subdomains).
- `firstPartyDomain`
- : A `string` representing the first-party domain with which the cookie to retrieve is associated.

This property must be supplied if the browser has first-party isolation enabled. If you pass `null`, cookies with any value for `firstPartyDomain` and cookies that do not have `firstPartyDomain` set are included in the results. See [First-party isolation](/docs/Mozilla/Add-ons/WebExtensions/API/cookies#first-party_isolation).

- `name`
- : A `string` representing a name that the cookies must have.
- `partitionKey`
- : An `object` defining which [storage partitions](/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning) to return cookies from:
- If omitted, only cookies from unpartitioned storage are returned.
- If included without `topLevelSite`, all cookies from partitioned and unpartitioned storage are returned.
- If included with the specified `topLevelSite`, cookies from the specified partition storage are returned.

This object contains:
- `topLevelSite`
- : A `string` representing the first-party URL of the top-level site storage partition containing the cookies.

- `path`
- : A `string` representing a path — the cookies' path must be identical to this one.
- `secure`
- : A `boolean` — filters cookies by their `secure` property, allowing you to filter secure or non-secure cookies.
- `session`
- : A `boolean` — filters the cookies by their `session` property, allowing you to filter session or persistent cookies.
- `storeId`
- : A `string` representing the cookie store to retrieve cookies from. If omitted, the current execution context's cookie store is used.
- `url`
- : A `string` representing a URL that the retrieved cookies must be associated with.

### Return value

A [`Promise`](/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is fulfilled with an array of cookies.Cookie objects that match the properties given in the `details` parameter. Only unexpired cookies are returned. The cookies returned are sorted by path length, longest to shortest. If multiple cookies have the same path length, those with the earliest creation time are first.

> [!NOTE]
> Before Firefox 133, Firefox returned the cookie sorted by creation time, with the earliest creation time first.

## Examples

This example gets all of the cookies the browser has stored with the name "favorite-color". When the result is returned, the code prints the value of each result to the console.

```js
function logCookies(cookies) {
for (const cookie of cookies) {
console.log(cookie.value);
}
}

browser.cookies
.getAll({
name: "favorite-color",
})
.then(logCookies);
```

## Browser compatibility

> [!NOTE]
> This API is based on Chromium's [`chrome.cookies`](https://developer.chrome.com/docs/extensions/reference/api/cookies#method-getAll) API. This documentation is derived from [`cookies.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/cookies.json) in the Chromium code.

<!--
// Copyright 2015 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

source: MDN Web Docs mirror · page

Cite this

"cookies.getAll()". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/getAll

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·