I'm trying to send a Chrome notification from my server, but I'm getting this message from the node sdk:
Promise { <pending> }
This is my code:
const webpush = require('web-push');
var public_key = 'xxx';
var private_key = 'xxx';
webpush.setVapidDetails(
'mailto:example@gmail.com',
public_key,
private_key
);
var Subscription = {
endpoint: 'XXXX',
keys: {
p256dh: 'XXX',
auth: 'XXX=='
}
};
var options = "Yay it works."
webpush.setGCMAPIKey('XXXX');
webpush.sendNotification(Subscription, options);
And this is my service worker code:
'use strict';
self.addEventListener('push', function(event) {
console.log('[Service Worker] Push Received.');
console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);
const title = 'Push Codelab';
const options = {
body: 'Yay it works.',
icon: '../images/icon.png',
badge: '../images/badge.png'
};
const notificationPromise = self.registration.showNotification(title, options);
event.waitUntil(notificationPromise);
});
via Filipe Ferminiano
No comments:
Post a Comment