cookies.get()

The get() method of the cookies API retrieves information about a cookie, given the cookie's name and URL.

To use this method, an extension must have the "cookies" permission and relevant host permissions. See cookie permissions for more details.

If there is more than one cookie with the same name for a URL, the cookie with the longest path is returned. For cookies with the same path length, the cookie with the earliest creation time is returned. If no matching cookie is found, null is returned.

Note: Before Firefox 133, when there was more than one cookie with the same name, Firefox returned the cookie with the earliest creation time.

This is an asynchronous function that returns a Promise.

Syntax

js
let getting = browser.cookies.get(
  details                // object
)

Parameters

details

An object containing details that are used to match a cookie to be retrieved. It can include these properties:

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. See First-party isolation.

name

A string representing the name of the cookie to retrieve.

partitionKey Optional

An object representing the storage partition containing the cookie. Include this object with topLevelSite to obtain a cookie from partitioned storage. Otherwise, returns the cookie from unpartitioned storage. This object contains:

topLevelSite Optional

A string representing the first-party URL of the top-level site storage partition containing the cookie.

storeId Optional

A string representing the ID of the cookie store in which to look for the cookie (as returned by cookies.getAllCookieStores()). By default, the current execution context's cookie store is used.

url

A string representing the URL with which the cookie to retrieve is associated. This argument may be a full URL, in which case any data following the URL path (e.g., the query string) is ignored. If host permissions for this URL are not specified in the extension's manifest file, the API call fails.

Return value

A Promise that is fulfilled with a Cookie object containing details about the cookie, or null if the cookie is not found.

Examples

This example tries to get the cookie named "favorite-color" associated with the URL for the active tab:

js
function logCookie(cookie) {
  if (cookie) {
    console.log(cookie.value);
  }
}

function getCookie(tabs) {
  let getting = browser.cookies.get({
    url: tabs[0].url,
    name: "favorite-color",
  });
  getting.then(logCookie);
}

let getActive = browser.tabs.query({
  active: true,
  currentWindow: true,
});
getActive.then(getCookie);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
get
Chrome – Full support
Chrome 6 (Release date: 2010-09-02)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote Provides access to cookies from private browsing mode and container tabs since version 52.
footnote From Firefox 133, sorts cookies according to RFC 6265, section 5.4. This means the cookie with the longest matching path is returned; previously, the earliest created cookie was returned.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Partial support
Safari 14 – 17.6 (Release date: 2020-09-16)
footnote Partial support
footnote HttpOnly cookies are not retrieved.
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 48 (Release date: 2016-08-02)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 15 – 17.6 (Release date: 2021-09-20)
footnote Partial support
footnote HttpOnly cookies are not retrieved.
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
firstPartyDomain
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 59 (Release date: 2018-03-13)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 59 (Release date: 2018-03-13)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
partitionKey
Chrome – Full support
Chrome 119 (Release date: 2023-10-31)
footnote Full support
Edge – Full support
Edge 119 (Release date: 2023-11-02)
footnote Full support
Firefox – Full support
Firefox 94 (Release date: 2021-11-02)
footnote Full support
Opera – Full support
Opera 105 (Release date: 2023-11-14)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 94 (Release date: 2021-11-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.

Note: This API is based on Chromium's chrome.cookies API. This documentation is derived from cookies.json in the Chromium code.