PushSubscription: toJSON() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Phương thức toJSON() của giao diện PushSubscription là một
bộ tuần tự hóa chuẩn: nó trả về biểu diễn JSON của các thuộc tính đăng ký,
cung cấp một lối tắt hữu ích.
Cú pháp
js
toJSON()
Tham số
Không có.
Giá trị trả về
Một đối tượng JSON. Đối tượng này chứa điểm cuối của đăng ký, expirationTime và các khóa công khai, dưới dạng một thành viên endpoint, một thành viên expirationTime và một thành viên keys.
Ví dụ
js
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.getSubscription().then((subscription) => {
const mySubscription = subscription.toJSON();
// thực hiện một việc gì đó với chi tiết đăng ký
});
});
Thông số kỹ thuật
| Specification |
|---|
| Push API> # dom-pushsubscription-tojson> |