True if the cookie is a host-only cookie (i.e. a request's host must exactly match the domain of the cookie).

string

path

The path of the cookie.

boolean

secure

True if the cookie is marked as Secure (i.e. its scope is limited to secure channels, typically HTTPS).

boolean

httpOnly

True if the cookie is marked as HttpOnly (i.e. the cookie is inaccessible to client-side scripts).

boolean

session

True if the cookie is a session cookie, as opposed to a persistent cookie with an expiration date.

double

(optional)
expirationDate

The expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies.

string

storeId

The ID of the cookie store containing this cookie, as provided in getAllCookieStores().

CookieStore

Represents a cookie store in the browser. An incognito mode window, for instance, uses a separate cookie store from a non-incognito window.

properties

string

id

The unique identifier for the cookie store.

array of integer

tabIds

Identifiers of all the browser tabs that share this cookie store.

OnChangedCause

Enum

"evicted",
"expired",
"explicit",
"expired_overwrite",
or "overwrite"

The underlying reason behind the cookie's change. If a cookie was inserted, or removed via an explicit call to "chrome.cookies.remove", "cause" will be "explicit". If a cookie was automatically removed due to expiry, "cause" will be "expired". If a cookie was removed due to being overwritten with an already-expired expiration date, "cause" will be set to "expired_overwrite". If a cookie was automatically removed due to garbage collection, "cause" will be "evicted". If a cookie was automatically removed due to a "set" call that overwrote it, "cause" will be "overwrite". Plan your response accordingly.

Methods

get

chrome.cookies.get(object details, function callback)

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.

Parameters

object

details

Details to identify the cookie being retrieved.

string

url

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.

string

name

The name of the cookie to retrieve.

string

(optional)
storeId

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.

Contains details about the cookie. This parameter is null if no such cookie was found.

getAll

chrome.cookies.getAll(object details, function callback)

Retrieves all cookies from a single cookie store that match the given information. The cookies returned will be sorted, with those with the longest path first. If multiple cookies have the same path length, those with the earliest creation time will be first.

Parameters

object

details

Information to filter the cookies being retrieved.

string

(optional)
url

Restricts the retrieved cookies to those that would match the given URL.

string

(optional)
name

Filters the cookies by name.

string

(optional)
domain

Restricts the retrieved cookies to those whose domains match or are subdomains of this one.

string

(optional)
path

Restricts the retrieved cookies to those whose path exactly matches this string.

boolean

(optional)
secure

Filters the cookies by their Secure property.

boolean

(optional)
session

Filters out session vs. persistent cookies.

string

(optional)
storeId

The cookie store to retrieve cookies from. If omitted, the current execution context's cookie store will be used.

set

Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.

Parameters

object

details

Details about the cookie being set.

string

url

The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie. If host permissions for this URL are not specified in the manifest file, the API call will fail.

string

(optional)
name

The name of the cookie. Empty by default if omitted.

string

(optional)
value

The value of the cookie. Empty by default if omitted.

string

(optional)
domain

The domain of the cookie. If omitted, the cookie becomes a host-only cookie.

string

(optional)
path

The path of the cookie. Defaults to the path portion of the url parameter.

boolean

(optional)
secure

Whether the cookie should be marked as Secure. Defaults to false.

boolean

(optional)
httpOnly

Whether the cookie should be marked as HttpOnly. Defaults to false.

double

(optional)
expirationDate

The expiration date of the cookie as the number of seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie.

string

(optional)
storeId

The ID of the cookie store in which to set the cookie. By default, the cookie is set in the current execution context's cookie store.

function

(optional)
callback

If you specify the callback parameter, it should
be a function that looks like this:

Events

onChanged

Fired when a cookie is set or removed. As a special case, note that updating a cookie's properties is implemented as a two step process: the cookie to be updated is first removed entirely, generating a notification with "cause" of "overwrite" . Afterwards, a new cookie is written with the updated values, generating a second notification with "cause" "explicit".