cookies.get()

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

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

This is an asynchronous function that returns a Promise.

Syntax

var getting = browser.cookies.get(
  details                // object
)

Parameters

details
An object containing details that can be used to match a cookie to be retrieved. It can include the following properties:
firstPartyDomainOptional
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.
storeIdOptional
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 will be 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 simply ignored. If host permissions for this URL are not specified in the extension's manifest file, the API call will fail.

Return value

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support YesEdge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Provides access to cookies from private browsing mode and container tabs since version 52.
Opera Full support YesFirefox Android Full support 48
firstPartyDomainChrome No support NoEdge No support NoFirefox Full support 59Opera No support NoFirefox Android Full support 59

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

Examples

This example tries to get the cookie named "favourite-colour", associated with the URL for the currently active tab:

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

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

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

Example extensions

Acknowledgements

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

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

Contributors to this page: wbamberg, andrewtruongmoz, Makyen, chrisdavidmills
Last updated by: wbamberg,