Search code examples
push-notificationprogressive-web-apps

pushsubscription gives options instead of keys when using requestSubscription()


I'm trying to follow this tutorial to enable push notifications in my PWA. According to the tutorial, I should get a pushSubscription object like this:

{
  "endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
  "expirationTime": null,
  "keys": {
    "p256dh": "BOXYnlKnMkzlMc6xlIjD8OmqVh-YqswZdut2M7zoAspl1UkFeQgSLYZ7eKqKcx6xMsGK7aAguQbcG9FMmlDrDIA=",
    "auth": "if-YFywyb4g-bFB1hO9WMw=="
  }
}

However when I inspect my subscription object I get something in the form of

{
  "endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
  "expirationTime": null,
  "options": {
    "applicationServerKey": ArrayBuffer(65),
    "userVisibleOnly": true
  }
}

note that I do not get the keys object and instead get an options object. Have the properties of the pushSubscription object changed? If I use this to send notifications, will it still work?


Solution

  • When saving my pushSubscription object with Mongoose, I used keys instead of options If I then inspect the object in my db (on MLab in my case) it looks like

    {
      "endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
      "expirationTime": null,
      "keys": {
        "p256dh": "BOXYnlKnMkzlMc6xlIjD8OmqVh-YqswZdut2M7zoAspl1UkFeQgSLYZ7eKqKcx6xMsGK7aAguQbcG9FMmlDrDIA=",
        "auth": "if-YFywyb4g-bFB1hO9WMw=="
      }
    }
    

    I guess that the object in my console is visualized differently, thus showing me the options parameter instead of keys.