cookies.get()

Retrieves information about a single cookie. If more than one cookie of the same name exists for the 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.

Syntax

browser.cookies.get(
  details,               // object
  function(cookie) {...} // function
)

Parameters

details
object. Details to identify the cookie being retrieved.
url
string. 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 manifest file, the API call will fail.
name
string. The name of the cookie to retrieve.
storeIdOptional
string. The ID of the cookie store in which to look for the cookie. By default, the current execution context's cookie store will be used.
callback
function. The function is passed the following arguments:
cookieOptional
cookies.Cookie. Contains details about the cookie. This parameter is null if no such cookie was found.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?45.0Yes33
Firefox
Basic support48.0

Examples

Callback-based version:

function got(cookie) {
  if (chrome.runtime.LastError) {
    console.error(chrome.runtime.LastError);
  } else {
    console.log(cookie);
  }  
}

chrome.cookies.get({
  url:"https://example.com/",
  name: "foo"
}, got);

Promise-based version:

function gotCookie(cookie) {
  console.log(cookie);  
}

function gotError(errorMessage) {
  console.error(errorMessage);
}

var getCookie = browser.cookies.get({
  url:"https://example.com/",
  name: "foo"
});

getCookie.then(gotCookie, gotError);

Acknowledgements

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

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,