CookieStoreManager:unsubscribe() 方法

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

备注: 此特性在 Service Worker 中可用。

CookieStoreManager 接口的 unsubscribe() 方法终止 ServiceWorkerRegistration 接收之前订阅的事件。

语法

js
unsubscribe(subscriptions)

参数

subscriptions

一个对象列表,每个对象包括以下属性:

name

记录 cookie 名称的字符串。

url

记录用于订阅 cookie 的 URL 作用域的字符串。

返回值

Service Worker 被取消订阅后兑现为 undefinedPromise

异常

TypeError

subscriptions 中的 URL 不匹配 Service Worker Registration 的作用域时抛出该异常。

示例

在此示例中,被 registration 指示的 ServiceWorkerRegistration 取消订阅 "/path1" 作用域下命名为 "cookie1" 的 cookie 的变更事件。

js
const subscriptions = [{ name: "cookie1", url: `/path1` }];
await registration.cookies.unsubscribe(subscriptions);

规范

Specification
Cookie Store API
# dom-cookiestoremanager-unsubscribe

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
unsubscribe

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support