The Notification() constructor creates a new Notification object instance, which represents a user notification.
new Notification(title)
new Notification(title, options)
In our Emogotchi demo (see source code), we run a spawnNotification() function when we want to trigger a notification. The function is passed parameters to specify the body, icon, and title we want, and then it creates the necessary options object and triggers the notification by using the Notification() constructor.
function spawnNotification(body, icon, title) {
const notification = new Notification(title, { body, icon });
}
Starting in Chrome 49, notifications don't work in incognito mode.
Chrome for Android will throw a TypeError when calling the Notification constructor. It only supports creating notifications from a service worker. See the Chromium issue tracker for more details.