content
-
listing
- h3Name
-
sample
- h3Name
-
API reference: Chrome. Cookies
-
attribute
- propertyName
-
methods
- get
- getAll
- getAllCookieStores
- remove
- set
-
The event
- onChanged
-
type
- Cookie
- CookieStore
-
For information on how to use experimental APIs, see the chrome.experimental.* APIs page.
Cookies
listing
To use the Cookies API, you must declare “cookies” permissions in your manifest, as well as any host permissions you want cookies to access. Such as:
{
"name": "My extension",
...
**"permissions": [
"cookies",
"*://*.google.com"
]**,
...
}
Copy the code
sample
You can find a simple example of using the cookies API in the examples/ API /cookies directory. For additional examples and help viewing the source code, see examples.
API reference: Chrome. Cookies
attribute
getLastError
chrome.extensionlastError
methods
get
void chrome.cookies.get(, object details
, function callback
)
Undocumented.
Get information about a cookie. If more than one cookie exists for a given URL, the cookie corresponding to the longest path is returned. For cookies with the same path length, the earliest cookie created is returned.
parameter
Details (optional enumerated Type array of object objects)
Undocumented.
The details used to identify the cookies received.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Url (optional enumerated Type array of string)
Undocumented.
The URL associated with the cookie received. This parameter can be a full URL, in which case any data (such as the query string) that follows the URL is ignored. If the host permissions for this URL are not set in the manifest file, the API call will fail.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Name (optional enumerated Type array of string String)
Undocumented.
The name of the cookie received.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
StoreId (optional enumerated Type array of string Optional, string)
Undocumented.
The storage ID of the cookie from which to retrieve the cookie. By default, the cookie store for the current execution context is used.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Callback (optional enumerated Type array of function functions)
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Returns
The callback function
If a callback argument is specified, it should specify a function like this:
If you specify the callback parameter, it should specify a function that looks like this:
function(Cookie cookie) {... };Copy the code
Cookie (optional enumerated cookie array of paramType) (Optional, cookie)
Undocumented.
Contains cookie details. If no cookie is found, this parameter is null.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
getAll
void chrome.cookies.getAll(, object details
, function callback
)
Undocumented.
Retrieves all cookies that match the given information from a cookie store. Cookies obtained are prioritized according to the longest path. When multiple cookies have paths of the same length, the earliest cookie is created first.
parameter
details
( optional enumerated Type array of object )
Undocumented.
Information for filtering cookies.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Url (optional enumerated Type array of string)
Undocumented.
Restrict the search to cookies that match a given URL.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Name (optional enumerated Type array of string optional, string)
Undocumented.
Filter cookies by name.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Domain (optional enumerated Type array of string)
Undocumented.
Restricts the search to cookies that match a given domain name or subdomain name.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Path (optional enumerated Type array of string)
Undocumented.
Restrict the search to cookies that match exactly the given path.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Secure (optional enumerated Type array of Boolean)
Undocumented.
Filters based on the Secure property of the cookie.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Session (optional enumerated Type array of Boolean)
Undocumented.
Filters based on whether the cookie’s lifetime is conversational or persistent.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
StoreId (optional enumerated Type array of string Optional, string)
Undocumented.
The storage ID of the cookie from which to retrieve the cookie. By default, the cookie store for the current execution context is used.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
callback
( optional enumerated Type array of function )
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Returns
The callback function
If a callback argument is specified, it should specify a function like this:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of Cookie cookies) {... };Copy the code
Cookies (optional enumerated Type array of Cookie array of paramType paramType Optional, Cookie list)
Undocumented.
A list of all cookies that match the given cookie information and exist that have not expired.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
getAllCookieStores
void chrome.cookies.getAllCookieStores(, function callback
)
Undocumented.
Enumerates all existing cookie stores.
parameter
callback
( optional enumerated Type array of function )
Undocumented.
Description of this parameter from the json schema.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
Returns
The callback function
If a callback argument is specified, it should specify a function like this:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of CookieStore cookieStores) {... };Copy the code
CookieStores (optional enumerated Type array of CookieStore)
Undocumented.
All existing cookies are stored.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
remove
void chrome.cookies.remove(, object details
)
Undocumented.
Delete cookies by name.
parameter
details
( optional enumerated Type array of object )
Undocumented.
Information used to identify the cookie to be deleted.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
url
( optional enumerated Type array of string )
Undocumented.
The URL associated with the cookie received. If the host permissions for this URL are not set in the manifest file, the API call will fail.
This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won’t be run in an earlier browser version.
name
( optional enumerated Type array of string )
Undocumented.