Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceWorker and Push Notification Payload

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!!!!

like image 778
Cristian Rinaldi Avatar asked Jun 29 '26 08:06

Cristian Rinaldi


1 Answers

  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.
like image 142
Jeff Posnick Avatar answered Jul 01 '26 01:07

Jeff Posnick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!