These two methods defined by the Push API are used to get the push subscription from the browser. What is the difference between them?
The answer is simple:
- PushManager.subscribe() creates a new subscription or returns the current subscription if it already exists (note that it never changes the current subscription if it already exists, so it’s safe to call it multiple times)
- PushManager.getSubscription() returns the existing subscription if it exists, otherwise returns
PushManager.subscribe() may trigger a permission prompt, if the user has not allowed the notifications yet, while
PushManager.getSubscription() will never trigger it.