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:
cookies.OnChangedCause
of overwrite
.cookies.OnChangedCause
of explicit
.browser.cookies.onChanged.addListener(listener) browser.cookies.onChanged.removeListener(listener) browser.cookies.onChanged.hasListener(listener)
This API is also available as browser.cookies.onChanged.*
.
Events have three functions:
addListener(callback)
removeListener(listener)
listener
argument is the listener to remove.hasListener(listener)
listener
is registered for this event. Returns true
if it is listening, false
otherwise.callback
A callback function that will be called when this event occurs. The function will be passed the following arguments:
changeInfo
object
containing details of the change that occurred. Its properties are as follows:removed
boolean
that is set to true
if a cookie was removed, and false if not.cookie
cookies.Cookie
object containing information about the cookie that was set or removed.cause
cookies.OnChangedCause
value representing the underlying reason behind the cookie's change.Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onChanged |
Yes |
79 |
45 |
? |
Yes |
No |
? |
? |
48 |
? |
? |
? |
partitionKey |
No |
No |
94 |
? |
No |
No |
? |
? |
94 |
? |
? |
? |
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); });
Note: 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.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/onChanged