Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

cookies.onChanged

The onChanged event of the cookies API is fired when a cookie is set or removed.

Note that updating a cookie's properties is implemented as a two step process:

  1. First, the cookie to be updated is first removed entirely, generating a notification with a cookies.OnChangedCause of overwrite.
  2. Next, a new cookie is written with the updated values, generating a second notification with a cookies.OnChangedCause of explicit.

Syntax

chrome.cookies.onChanged.addListener(function(
  changeInfo // object
) {...})

chrome.cookies.onChanged.removeListener(listener)
chrome.cookies.onChanged.hasListener(listener)

This API is also available as browser.cookies.onChanged.*.

Events have three functions:

addListener(callback)
Adds a listener to this event.
removeListener(listener)
Stop listening to this event. The listener argument is the listener to remove.
hasListener(listener)
Check whether listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

callback

A callback function that will be called when this event occurs. The function will be passed the following arguments:

changeInfo
An object containing details of the change that occurred. Its properties are as follows:
removed
A boolean that is set to true if a cookie was removed, and false if not.
cookie
A cookies.Cookie object  containing information about the cookie that was set or removed.
cause
A cookies.OnChangedCause value representing the underlying reason behind the cookie's change.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 45.0 48.0 33

Examples

This example listens for onChanged evenets and logs details from the changeInfo argument:

chrome.cookies.onChanged.addListener(function(changeInfo) {
  console.log('Cookie changed: ' +
              '\n * Cookie: ' + JSON.stringify(changeInfo.cookie) +
              '\n * Cause: ' + changeInfo.cause +
              '\n * Removed: ' + changeInfo.removed);
});

Example add-ons

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: Makyen, wbamberg, chrisdavidmills
 Last updated by: Makyen,