question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PushManager.subscribe() needs applicatonServerKey option.

See original GitHub issue

Please check the following links: https://tools.ietf.org/html/draft-thomson-webpush-vapid-02#page-6 https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe

I believe option is necessary to send encrypted messages.

The server key is currently used for WebPusher.encode()

The comment says


The server key is an ephemeral ECDH key used only for this transaction

However, I believe this key is not only for this transaction but also for the subscribe method.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jpjitendrapalcommented, Jul 11, 2018

to get object data from subscription you can use: JSON.parse(JSON.stringify(subscription))

0reactions
jrconlincommented, Aug 26, 2016

Sorry, got pulled into a few things. You should be able to call subscription.getKey('auth') from the push subscription object returned by registration.pushManager.subscribe(). If it’s any help, you can look at what I do in the Web Push Data Test Page. I’ll also be honest, I’ve not really checked if I’m being smart about how I do things in pywebpush if you’re not sending data. Mostly because not sending data is a LOT easier. You just do a POST to the endpoint you’ve gotten. No worries about the weird headers, no encryption dance. Heck, you don’t even need to get the various keys from the subscription. All you need to do is pass the VAPID info (if you want, again, not needed) and a TTL (Time To Live for the notification). I’ve got a write up that describes a lot of this (probably in WAY more detail than most folks want) That link drops you off into the “Send A Push Notification With No Data” bit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PushManager.subscribe() - Web APIs | MDN
The subscribe() method of the PushManager interface subscribes to a push service. It returns a Promise that resolves to a PushSubscription ...
Read more >
Subscribing a User - web.dev
First we need to check if the current browser actually supports push ... The applicationServerKey option passed into the subscribe() call is ...
Read more >
Beginners guide to Web Push Notifications using Service ...
Push notifications are very common in the native mobile application platforms like Android & iOS. The are most effective ways to re-engage ...
Read more >
builtins.PushManager.subscribe JavaScript and Node.js code ...
log('Service worker is registired'); const subscription = await register.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: ...
Read more >
Changing application server key in push manager subscription
Get the subscription using reg.pushManager.getSubscription() and check whether current subscription uses the new application server key.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found