cookies.getAll()
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 for more details.
This is an asynchronous function that returns a Promise
.
Syntax
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 for more information on these):domain
Optional-
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
Optional-
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 forfirstPartyDomain
and cookies that do not havefirstPartyDomain
set are included in the results. See First-party isolation. name
Optional-
A
string
representing a name that the cookies must have. partitionKey
Optional-
An
object
defining which storage partitions 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
Optional-
A
string
representing the first-party URL of the top-level site storage partition containing the cookies.
path
Optional-
A
string
representing a path — the cookies' path must be identical to this one. secure
Optional-
A
boolean
— filters cookies by theirsecure
property, allowing you to filter secure or non-secure cookies. session
Optional-
A
boolean
— filters the cookies by theirsession
property, allowing you to filter session or persistent cookies. storeId
Optional-
A
string
representing the cookie store to retrieve cookies from. If omitted, the current execution context's cookie store is used. url
Optional-
A
string
representing a URL that the retrieved cookies must be associated with.
Return value
A Promise
that is fulfilled with an array of
objects that match the properties given in the cookies.Cookie
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.
function logCookies(cookies) {
for (const cookie of cookies) {
console.log(cookie.value);
}
}
browser.cookies
.getAll({
name: "favorite-color",
})
.then(logCookies);
Example extensions
Browser compatibility
BCD tables only load in the browser
Note: This API is based on Chromium's chrome.cookies
API. This documentation is derived from cookies.json
in the Chromium code.