Open Bug 1098223 Opened 10 years ago Updated 2 years ago

Notification API close to fire too early

Categories

(Core :: DOM: Core & HTML, defect, P5)

33 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: Krassmus, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0
Build ID: 20141013200324

Steps to reproduce:

I used Web Notification API to display a notification to a user (me).


Actual results:

The notification was clearly visible for a few seconds and disappears afterwards. That is okay to me. But in fact the onclose-event of the notification was fired, when the notification disappears, even if there was no user-interaction at all. My page now also has a notification in-page that shows the user that there is something new. And the page is displacing this in-page notification when the desktop-notification fires onclose.

That means, if I am absent from my computer and turn back all notifications are gone and my page which fired them received lots of onclose-events so that the page thinks that all notifications have been seen by the user, which the user has not.


Expected results:

The onclose event should only be fired if the user clicks on the X of the notification, but not if the notification silently disappears after a few seconds. The onclose event should never be fired without any user-interaction.

I know that there is nothing about this in the specs. But chrome handles the notifications differently. And as a webdeveloper I need to know if the X is clicked so that the notification should not be displayed anymore.
Fun.

The whatwg spec says nothing about this, you're right.

The w3c "TR" (which I'm told I (as a triager) shouldn't normally look at), however, specifies:

http://www.w3.org/TR/notifications/#closing-a-notification

>>>
When a notification is closed, ****either by the underlying notifications platform or by the user***, the close steps for it must be run.

The close steps for a given notification are:

1)    If notification is neither in the list of pending notifications nor in the list of active notifications, terminate these steps.

2)    Queue a task to remove notification from either the list of pending notifications or the list of active notifications, and fire an event named close on notification. 
<<<

But yes, I also agree that as a web dev, I might be more interested in the user dismissing the notification than in the platform auto-dismissing it.

Anne, you're listed as an editor for the w3c version... can you help?
Component: Untriaged → DOM
Flags: needinfo?(annevk)
OS: Linux → All
Product: Firefox → Core
Hardware: x86_64 → All
Looks like the close event was removed from the whatwg version entirely...

https://github.com/whatwg/notifications/commit/53ebcf25458f7581570a228cfa11ad7cb27ff4ea
Based on discussion in the WHATWG list we changed the API quite a bit, including no longer making notifications persistent.

If you want persistent notifications, you'll need to use service workers. I'm not aware of this being implemented already and the fact that we still dispatch close events indicates we haven't implemented all changes yet.
Flags: needinfo?(annevk)
Note that we aim to implement https://notifications.spec.whatwg.org/ in Gecko.
So if the close-event is removed from the specs and I as the webdev have no feedback channel from the X (dismiss the notification) that'll be okay for me. Not perfect though, but okay.
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
This is still a bug, and a really nasty one. "notificationclose" is fired (in a service worker) for 3 different reasons, and there is no way to differentiate between these:

* User clicked "x" button to close the notification
* Firefox dismisses the notification
* The notification is replaced with a new notification with the same tag



I'm trying to implement a "synchronized notifications" system where notifications are synchronized between devices. It's impossible with this behaviour.

This is the code I'm using the capture the close events in the service worker:

self.addEventListener('notificationclose', function (event) {
  console.log('On notification close: ', event.notification.tag);
});



Does anyone have a solution for this?
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.