ExtendableCookieChangeEvent:changed 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
备注: 此特性仅在 Service Worker 中可用。
ExtendableCookieChangeEvent 接口的 changed 只读属性返回给定 ExtendableCookieChangeEvent 实例已变更的 cookie。
值
一个包含已变更的 cookie 的对象数组。每个对象包含以下属性:
name-
记录 cookie 名称的字符串。
value-
记录 cookie 的值的字符串。
domain-
记录 cookie 域名的字符串。
path-
记录 cookie 路径的字符串。
expires-
Unix 时间戳(以毫秒为单位表示),记录 cookie 的到期日期。
secure-
一个布尔值,表示 cookie 是否仅在安全上下文中使用(HTTPS 而不是 HTTP)。
sameSite-
以下
SameSite的值之一: partitioned-
一个布尔值,表示 cookie 是否是分区 cookie(
true)或(false)。更多信息请参阅具有独立分区状态的 Cookie(CHIPS)。
示例
此示例中,在 cookie 被设置时,事件监听器打印 changed 属性至控制台。数组的第一个元素代表刚被设置的 cookie 的对象。
js
self.addEventListener("cookiechange", (event) => {
console.log(event.changed[0]);
});
const one_day = 24 * 60 * 60 * 1000;
cookieStore.set({
name: "cookie1",
value: "cookie1-value",
expires: Date.now() + one_day,
domain: "example.com",
});
规范
| Specification |
|---|
| Cookie Store API> # dom-extendablecookiechangeevent-changed> |
浏览器兼容性
Loading…