Azure notifications hub for browser - browser is not receiving notifications

Voila Team 1 Reputation point
2023-12-16T15:34:51.6433333+00:00

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.

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
264 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 18,366 Reputation points
    2023-12-19T08:40:48.29+00:00

    @Voila Team Thanks for reaching here!

    It seems you are encountering issues with Azure Notification Hubs. To troubleshoot the issue and to get more error information about the failed delivery attempt against a registration, you can use the Notification Hubs REST APIs Per Message Telemetry: Get Notification message telemetry and PNS feedback.

    For sample code, see the Send REST example.

    Suggest you follow this detailed official document on Diagnose dropped notifications in Azure Notification Hubs would be helpful.

    Let us know.

    0 comments No comments