The notification API provides a number of configuration options to customize the look and feel of the notification. You can also define the custom actions that enable users to execute some quick actions from the notification itself. Custom actions can be added to the notification just by passing the action array in to the showNotification
method:
const title = 'Actions Notification'; const options = { actions: [ { action: 'coffee-action', title: 'Coffee', icon: '/images/demos/action-1-128x128.png' }, { action: 'doughnut-action', title: 'Doughnut', icon: '/images/demos/action-2-128x128.png' } ] }; options.body = `This notification can displays action button `; registration.showNotification(title, options);
This will show the action button in the notification, similar to the following image:
To handle the actions inside the notification, you need to handle the notification click...