Hello,
I have encountered some issues with Azure Notifications Hub and would appreciate your guidance in resolving them.
To provide some context, I have already configured the VAPID Keys and installed my browser using the API mentioned here:
And installed my browser using this API:
https://learn.microsoft.com/en-us/rest/api/notificationhubs/create-registration
with this body:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<BrowserRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Endpoint>https://fcm.googleapis.com/fcm/send/.....</Endpoint>
<P256DH>{P256DH-value}</P256DH>
<Auth>{Auth-value}</Auth>
</BrowserRegistrationDescription>
</content>
</entry>
Additionally, I attempted to register my browser using JavaScript with the following code:
navigator.serviceWorker.register("service-worker.js");
Notification.requestPermission().then((permission) => {
if (permission === 'granted') {
// get service worker
navigator.serviceWorker.ready.then((sw) => {
// subscribe
sw.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: "VAPID_PUBLIC_KEY"
}).then((subscription) => {
let data = JSON.parse(JSON.stringify(subscription));
console.log(data);
});
});
}
});
In the service-worker.js
file, I have included the following code to handle push events:
self.addEventListener("push", (event) => {
console.log(event);
console.log(event.data);
const notification = event.data.json();
event.waitUntil(self.registration.showNotification(notification.title, {
body: notification.body,
icon: "icon.png",
data: {
notifURL: notification.url
}
}));
});
Despite my efforts, I am not receiving any events, and the test sends always fail. I kindly request your assistance in troubleshooting and resolving these issues.
Thank you in advance for your support.