I want to send push notification from node js to chrome browser of my android device.Is that possible? If so, how to achieve it? Thanks in advance.
1 Answer
have a look at pretty module web-push You need to have GCM API key and VAPID key, which module helps you to generate for the first time.
const webpush = require('web-push');
// VAPID keys should only be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('<Your GCM API Key Here>');
webpush.setVapidDetails(
'mailto:[email protected]',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '.....'
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text');
Good luck!
2 Comments
Vishal Patel
Thanks Dima! I try your solution and it works in my desktop but not in chrome browser of my mobile. Any solution?