NOTIFICATIONS API
The Notifications API, as its name suggests, is used to display notifications to the user. In many ways, notifications are similar to alert()
dialogue boxes: both use a JavaScript API to trigger browser behavior outside of the page itself, and both allow the page to handle the various ways in which users interact with the dialogue boxes or notification tiles. Notifications, however, offer a far greater degree of customizability.
The Notifications API is especially useful in the context of service workers. It allows a progressive web application (PWA) to behave more like a native app by triggering notifications to show even when a browser page is not active.
Notification Permissions
The Notification API has the potential for abuse, so it enforces two security features by default:
- Notifications can be triggered only by code executing in a secure context.
- Notifications must be explicitly allowed by the user on a per-origin basis.
The user grants notification permission...