PushSubscription.toJSON()
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The toJSON()
method of the PushSubscription
interface is a
standard serializer: it returns a JSON representation of the subscription properties,
providing a useful shortcut.
Syntax
mySubscription = subscription.toJSON()
Parameters
None.
Returns
A JSON object. It currently only contains the subscription endpoint, as an
endpoint
member.
Example
navigator.serviceWorker.ready.then(function(reg) {
reg.pushManager.getSubscription().then(function(subscription) {
var mySubscription = subscription.toJSON();
// do something with subscription details
})
});
Specifications
Specification |
---|
Push API # dom-pushsubscription-tojson |
Browser compatibility
BCD tables only load in the browser