Contact emails
Spec
Summary
Enabling delivery of Web Notification-generated events to a Service Worker.
Motivation
Notifications play a prominent role of informing the user of activities and events on mobile, but the expected lifetime of a document on a mobile device would make them very unreliable at best. This causes the page to lose the event handlers, making it impossible for the user to respond to a shown notification.
Instead, it will be possible to create Service Worker-bound notifications. These will be created using a method on the ServiceWorkerRegistration instead of the Notification constructor, and will move event delivery of the "click" and "error" events to the Service Worker rather than event handlers on the Notification event itself. Such notifications can safely outlive the page or worker they were created by, without rendering them useless.
When the user clicks on a Service Worker-bound notification, the browser will activate the Service Worker and invoke the "onnotificationclick" event. It's got full access to the Notification object from here.
Example
// index.html
navigator.serviceWorker.ready.then(function (registration) {
registration.showNotification('Hello, world!', {
body: 'This is a notification.',
icon: 'notification.png'
});
});
// service_worker.js
onnotificationclick = function(event) {
if (event.notification.title == 'Hello, world!') {
// do something with it.
event.notification.close();
}
};
Compatibility Risk
Small. Mozilla is pushing for the Service Worker event delivery as well. Neither Microsoft nor Apple have participated in discussions.
Will this feature be supported on all five Blink platforms?
Yes.
OWP launch tracking bug?
Link to entry on the feature dashboard
Requesting approval to ship?
No.