onChanged
event of the
Cookie
API fires when a cookie that the extension can access is set or removed.
注意:
当
storage partitioning
is active,
cookies.Cookie.partitionKey
contains the description of the cookie's storage partition. When modifying cookies, it's important to pass this value to
cookies.set()
or
cookies.remove()
to ensure the extension works with the correct cookie.
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)
Adds a listener to this event.
removeListener(listener)
Stop listening to this event. The
listener
argument is the listener to remove.
hasListener(listener)
校验是否
listener
is registered for this event. Returns
true
if it is listening,
false
否则。
callback
A callback function that will be called when this event occurs. The function will be passed the following arguments:
changeInfo
An
对象
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.
BCD tables only load in the browser
This example listens for
onChanged
events and logs details from the
changeInfo
自变量:
browser.cookies.onChanged.addListener(function(changeInfo) {
console.log('Cookie changed: ' +
'\n * Cookie: ' + JSON.stringify(changeInfo.cookie) +
'\n * Cause: ' + changeInfo.cause +
'\n * Removed: ' + changeInfo.removed);
});
注意:
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.
最后修改: , 由 MDN 贡献者