If a notification with the requireInteraction flag not set is left and is automatically removed, should the notificationclose event fire
If a persistent notification with the require Interaction flag not set is left and is automatically removed from the display, should the notificationclose event fire? I think it should.
Right now in Chrome it does not, and looking at the spec and https://github.com/whatwg/notifications/issues/52 it is not clear if it should or not (the language I think is a little vague).
The spec says wrt to require interaction flag:
When set, indicates that on devices with a sufficiently large screen, the notification should remain readily available until the user activates or dismisses the notification.
The spec also says close steps should only apply to persistent notifications when the user or system dismisses the notification, and a persistent notification is a notification with an attached service worker.
Checking Chrome's implementation, when in a service worker there is a notification on the screen self.registration.getNotifications().then(function(e) {console.log(e);}) will list the notification objects, when the timeout for the display occurs self.registration.getNotifications().then(function(e) {console.log(e);}) will then have an empty list. This implies the item has been removed from the notification list and should have the event fired. But chrome I think is spec compliant in this case.
In my head at least, there needs to be clarity around the definition of the requireInteractionFlag should say 'the notification should remain in the list of notifications until the user activates or dismisses the notification', without this it is not saying clearly that the close steps should be run or not when the system times out notification.
Spoke to @beverloo out of band and at least in the implementation it is intended. If this is also the intention of the spec it would be good to clear up the language a little in the requireInteractionFlag section to indicate that it will not raise a SW event, right now (unless I am mistaken) it is inferred.
Your initial post is a little confusing. If the flag is not set I would not expect events necessarily. If it is set, it seems weird for the browser to dismiss the notification after some time. Could you clarify what scenario you mean?
The former, so to clarify the thinking after talking to @beverloo :
- requireInteraction: undefined -> no notificationclose event if platform auto-dismisses
- requireInteraction: false -> no notificationclose event if the platform auto-dismisses? <- or is it by explicitly setting we are knowingly opting in to auto-dismiss and thus get events?
- requireInteraction: true -> platform will not auto-dismiss so all close events will fire the notificationclose when the notification is dismissed
My questioning is more around the language in the spec. If the above three points are accurate it would be nice to clarify them. Or if they are not accurate, also clarify it. Right now when I read through the spec I inferred that it might fire the event when the system auto-dismisses, but speaking to peter said they shouldn't.
requireInteraction can only be true or false per the specification. There is no third state (not passing it is false).