Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil). Junte-se a nós e ajude-nos a fazer o trabalho!
Você também pode ler o artigo em English (US).

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.



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

Events have three functions:

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

addListener syntax



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

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

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxOperaFirefox for Android
onChangedChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48


Full support  
Full support
No support  
No support


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

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

Example extensions


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.

Etiquetas do documento e colaboradores

Colaboradores desta página: mdnwebdocs-bot, wbamberg, EddieFloresLive, Makyen, chrisdavidmills
Última atualização por: mdnwebdocs-bot,