JSFiddle - React, Tailwind, and code Playground

by wrxsti85

JavaScript

// https://developer.mozilla.org/en-US/docs/Web/API/notification
// https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
var notif = function() {
    this.permission = function(callback) {
        Notification.requestPermission().then(function(result) {
        	if(result === 'granted') callback(1000);
        });
    };
    this.testNotification = function(delay) {
        setTimeout(function() {
            var notification = new Notification('Chat Support', {
                body: 'You have received a message!',
                icon: 'https://www.1and1.com/logo.png'
            });
        }, delay);
    };
};

var n = new notif();
if (Notification.permission != 'granted') {
    n.permission(n.testNotification);
} else {
    n.testNotification(1000);
}