0

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
  • you use SNS service for sending notification Commented Jan 22, 2020 at 4:29

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Dima! I try your solution and it works in my desktop but not in chrome browser of my mobile. Any solution?
this too?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.