CookieStoreManager: phương thức unsubscribe()

Limited availability

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

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Service Workers.

Phương thức unsubscribe() của giao diện CookieStoreManager ngừng để ServiceWorkerRegistration nhận các sự kiện đã đăng ký trước đó.

Cú pháp

js
unsubscribe(subscriptions)

Tham số

subscriptions

Một danh sách đối tượng, mỗi đối tượng chứa:

name

Một chuỗi chứa tên của cookie.

url

Một chuỗi chứa URL của phạm vi được dùng để đăng ký với cookie này.

Giá trị trả về

Một Promise được phân giải với undefined khi service worker đã được hủy đăng ký.

Ngoại lệ

TypeError

Được ném ra nếu URL được truyền trong subscriptions không khớp với scope của đăng ký service worker.

Ví dụ

Trong ví dụ này, ServiceWorkerRegistration được biểu diễn bởi registration hủy đăng ký nhận các sự kiện thay đổi trên cookie có tên "cookie1" với phạm vi là "/path1".

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

Thông số kỹ thuật

Specification
Cookie Store API
# dom-cookiestoremanager-unsubscribe

Khả năng tương thích với trình duyệt