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
objectcontaining details that are used to match cookies to retrieve. Included properties are as follows (see Cookie type for more information on these):domainOptional-
A
stringrepresenting a domain that cookies must be associated with (they can be associated either with this exact domain or one of its subdomains). firstPartyDomainOptional-
A
stringrepresenting 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 forfirstPartyDomainand cookies that do not havefirstPartyDomainset are included in the results. See First-party isolation. nameOptional-
A
stringrepresenting a name that the cookies must have. partitionKeyOptional-
An
objectdefining 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:
topLevelSiteOptional-
A
stringrepresenting the first-party URL of the top-level site storage partition containing the cookies.
pathOptional-
A
stringrepresenting a path — the cookies' path must be identical to this one. secureOptional-
A
boolean— filters cookies by theirsecureproperty, allowing you to filter secure or non-secure cookies. sessionOptional-
A
boolean— filters the cookies by theirsessionproperty, allowing you to filter session or persistent cookies. storeIdOptional-
A
stringrepresenting the cookie store to retrieve cookies from. If omitted, the current execution context's cookie store is used. urlOptional-
A
stringrepresenting a URL that the retrieved cookies must be associated with.
Return value
A 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.
function logCookies(cookies) {
for (const cookie of cookies) {
console.log(cookie.value);
}
}
browser.cookies
.getAll({
name: "favorite-color",
})
.then(logCookies);
Example extensions
Browser compatibility
Loading…
Note:
This API is based on Chromium's chrome.cookies API. This documentation is derived from cookies.json in the Chromium code.