cookies
API 的 OnChangedCause
型別,代表觸發 cookie 資料變動的原因。
型別
此型別的所有值都是字串(string)。可用值包括:
evicted
- 由於垃圾回收(garbage collection)而被刪除的 cookie。
expired
- 由於過期而被刪除的 cookie。
explicit
- 透過顯式呼叫(explicit call)
cookies.remove()
而被插入或刪除的 cookie。 expired_overwrite
- 被已過期(already-expired expiration date)cookie 所覆寫的 cookie。
overwrite
- A call to
cookies.set()
overwrote this cookie with a different one.
瀏覽器相容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
示例
你可以在 cookie 變更的時候監聽被通知的 cookies.onChanged
事件。此監聽器 passed 含有 cause
屬性,值為 OnChangeCaused
字串的 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);
});
致謝
此 API 基於 Chromium 的 chrome.cookies
API 而來,文件改作自 Chromium 程式碼裡的 cookies.json
。
Microsoft Edge 的相容資訊來自微軟公司,原文以創用 CC 姓名標示 3.0 美國版條款授權大眾使用。