ServiceWorker and Push Notification Payload

1.1k views Asked by At

Community:

ServiceWorker is a great advance technology in terms of cache managment, but I have some questions associated with other operations such as:

Push Notification: I made a GCM integration (Google Clud Message) and NodeJS, following this article, the problem is that when GCM sends the information to the client (Chorme), the payload of the message generated by GCM is not accessible in the Notification in ServiceWorker Listener, which would be great for making decisions. Any Idea when data payload in notifications will be enabled?

Registration: Since ES6 is very mature, it would be good to register a ServiceWorker in other ways, for example:

import sw from './sw.js'

navigator.serviceWorker.register(sw, {scope: '/'}).then(function (registration) {
 // Registration was successful
 console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function (err) {
 // registration failed :(
 console.log('ServiceWorker registration failed: ', err);
});

Is this possible or make sense?

Thanks!!!!

1

There are 1 answers

1
Jeff Posnick On BEST ANSWER
  1. The "Support encrypted payloads for push messages" bug tracks progress on getting payloads exposed in notifications. That bug is Chrome-specific, but other browser vendors are likely to follow the same approach.
  2. The service worker upgrade flow is very much tied to the idea of there being a specific JavaScript file which represents the service worker's code, and that file can then be periodically checked, byte-by-byte, to see if there are any updates. If it were an in-memory JavaScript object that was registered, detached from the file, the upgrade flow wouldn't work as specified. I don't think you'll see the change you're proposing added to the specification.