chrome.cookies (original) (raw)

Skip to main content

chrome.cookies

Description

Use the chrome.cookies API to query and modify cookies, and to be notified when they change.

Permissions

cookies

To use the cookies API, declare the "cookies" permission in your manifest along with host permissions for any hosts whose cookies you want to access. For example:

{
  "name": "My extension",
  ...
  "host_permissions": [
    "*://*.google.com/"
  ],
  "permissions": [
    "cookies"
  ],
  ...
}

Partitioning

Partitioned cookies allow a site to mark that certain cookies should be keyed against the origin of the top-level frame. This means that, for example, if site A is embedded using an iframe in site B and site C, the embedded versions of a partitioned cookie from A can have different values on B and C.

By default, all API methods operate on unpartitioned cookies. ThepartitionKey property can be used to override this behavior.

For details on the general impact of partitioning for extensions, seeStorage and Cookies.

Examples

You can find a simple example of using the cookies API in theexamples/api/cookies directory. For other examples and for help in viewing the source code, see Samples.

Types

Represents information about an HTTP cookie.

Properties

CookieDetails

Details to identify the cookie.

Properties

CookiePartitionKey

Represents a partitioned cookie's partition key.

Properties

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

FrameDetails

Details to identify the frame.

Properties

OnChangedCause

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.

Enum

"evicted"

"expired"

"explicit"

"expired_overwrite"

"overwrite"

SameSiteStatus

A cookie's 'SameSite' state (https://tools.ietf.org/html/draft-west-first-party-cookies). 'no_restriction' corresponds to a cookie set with 'SameSite=None', 'lax' to 'SameSite=Lax', and 'strict' to 'SameSite=Strict'. 'unspecified' corresponds to a cookie set without the SameSite attribute.

Enum

"no_restriction"

"lax"

"strict"

"unspecified"

Methods

get()

chrome.cookies.get(
  details: CookieDetails,
): Promise<Cookie | undefined>

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

Returns

getAll()

chrome.cookies.getAll(
  details: object,
): Promise<Cookie[]>

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. This method only retrieves cookies for domains that the extension has host permissions to.

Parameters

Returns

getAllCookieStores()

chrome.cookies.getAllCookieStores(): Promise<CookieStore[]>

Lists all existing cookie stores.

Returns

getPartitionKey()

chrome.cookies.getPartitionKey(
  details: FrameDetails,
): Promise

The partition key for the frame indicated.

Parameters

Returns

remove()

chrome.cookies.remove(
  details: CookieDetails,
): Promise<object | undefined>

Deletes a cookie by name.

Parameters

Returns

set()

chrome.cookies.set(
  details: object,
): Promise<Cookie | undefined>

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

Parameters

Returns

Events

onChanged

chrome.cookies.onChanged.addListener(
  callback: function,
)

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".

Parameters

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-11 UTC.