Web push (or browser push) is a type of notification that customers get on their desktop browsers, or in some cases mobile browsers, on a per-website basis.
Azure Notification Hubs now supports browser push for all major browsers, including Microsoft Edge, Google Chrome, and Mozilla Firefox. Apple Safari isn't included. For Apple Safari, you can use existing APNS support as described in Configuring Safari Push Notifications, with certificate-based authentication.
Browser push is supported across platforms on devices with the following operating systems and browsers.
Browser push support on laptop computers:
Operating system
Browsers
Windows OS
Google Chrome v48+ Microsoft Edge v17+ Mozilla Firefox v44+ Safari v7+ Opera v42+
macOS
Chrome v48+ Firefox v44+ Safari v7+ Opera v42+
Linux OS
Chrome v48+ Firefox v44+ Safari v7+ Opera v42+
Browser push support on tablet PCs:
Operating system
Browsers
Windows OS
Chrome v48+ Firefox v44+ Opera v42+
iOS
Not supported.
Android OS
Chrome v48+ Firefox v44+ Opera v42+
Browser push support on mobile devices:
Operating system
Browsers
iOS
Not supported.
Android OS
Chrome v48+ Firefox v44+ Opera v42+
Set credentials
To subscribe to browser push notifications on your web site, you can use VAPID keys. You can generate VAPID credentials by using services such as the VAPID key generator. The credentials should look similar to the following:
To set browser push credentials in the Azure portal, follow these steps:
In the Azure portal, open the Browser (Web Push) blade in your notification hub.
Enter your existing VAPID keys, or generate a new VAPID key pair using a service such as the VAPID Key Generator.
Select Save.
Set credentials using REST API
You can also set the browser credentials for browser push by using the REST API, such as using the Create Or Update Hub REST API method, the Azure Resource Manager API, or the V2 RP.
Enter the credentials in this format, providing the subscription ID, resource group, namespace, and notification hub:
For a direct send, you'll need the endpoint URI, p25DH key, and auth secret from a browser subscription. For more information about direct send notifications, see Direct send.
To create a direct send notification, follow these steps:
Set the following headers for browser push:
ServiceBusNotification-Format - browser
ServiceBusNotification-DeviceHandle - endpoint: the endpoint field from the subscription
P256DH: the p256dh field from the subscription
Auth: the auth field from the subscription
Create the message body. The message body is typically in this format:
JSON
{
"title": "Some Title",
"body": "Some body of a message"
}
You can specify other fields in the body; for example, icon, to change the icon per message.
Send the notification.
You can also use the .NET SDK to create a direct send:
C#
var browserSubscriptionEndpoint = "";
var browserPushHeaders = new Dictionary<string, string>
{
{ "P256DH", "" },
{ "Auth", "" },
};
var directSendOutcome = await notificationHubClient.SendDirectNotificationAsync(new BrowserNotification("payload", browserPushHeaders), browserSubscriptionEndpoint);
Create audience sends
For an audience send, use the same ServiceBus Notification-Format header used for a direct send, and modify the message payload as desired. Optionally, specify a tag expression using the ServiceBusNotification-Tags header. For more information about creating an audience send, see Send an APNS native notification.
To create an audience send using the SDK, use the following statement:
C#
var outcome = await notificationHubClient.SendNotificationAsync(new BrowserNotification(payload, tagExpression);
Create debug/test sends
Debug sends are created in the Azure portal and require registrations and installations.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.