Replaced Notification onclick doesn't work
Reported by
bm.se...@gmail.com,
Sep 4
|
|||||||
Issue description
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Steps to reproduce the problem:
1. Open two tabs with same URL
2. create a notification in each tab with same tag with onclick
3. onclick isn't triggered
What is the expected behavior?
onclick should work
What went wrong?
When I create a notification in two tabs with same tag, the previous one is being replaced by the second but the second notification onclick isn't triggered.
try with this:
var notif = new Notification('a', {tag: '123'});
notif.onclick = function() {this.close()}
Did this work before? N/A
Chrome version: 68.0.3440.106 Channel: n/a
OS Version: 10
Flash Version: Shockwave Flash 30.0 r0
,
Sep 4
,
Sep 5
bm.sedat@ Thanks for the issue. Request you to provide a extension where a notification is created and onclick is triggered, which will help in further triaging of the issue. Thanks..
,
Sep 5
I'm sorry I couldn't understand.
To test:
1 - please allow notifications for this website.
2 - Right click tab on title bar -> Duplicate
The notification should be created in two tabs which have same URLs
3 - Open Developer Tools -> Console for each tab
4 - Paste and run following in both console
5 - Click on the Web Notification after 2nd tab runs the code
6 - Notice that it won't close.
The code:
var notification = new Notification('a', {tag: '123'});
notification.onclick = function() {this.close()}
If you run this code in only one tab, the onclick will run and ` this.close() ` will close the notification. If the URL is different there will be 2 different notification so it will work correct too. Only when the URLs are same in the tabs, this problem happens.
,
Sep 5
Thank you for providing more feedback. Adding the requester to the cc list. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Sep 5
,
Sep 5
When you replace a notification, the replaced version is effectively closed. Consider this:
===============
const notification1 = new Notification('a', { tag: '123' });
notification1.addEventListener('click', function() { console.log('1: click'); });
notification1.addEventListener('close', function() { console.log('1: close'); });
notification1.addEventListener('show', function() { console.log('1: show'); });
const notification2 = new Notification('b', { tag: '123' });
notification2.addEventListener('click', function() { console.log('2: click'); });
notification2.addEventListener('close', function() { console.log('2: close'); });
notification2.addEventListener('show', function() { console.log('2: show'); });
===============
The expected output of this is:
1: show
1: close
2: show
When clicking on the notification, you'll only get "2: click". The first notification is effectively closed.
,
Sep 5
Okay, this solves my problem.
notification2.onclick = function() { this.close() }
doesn't work but,
notification2.addEventListener('click', function() { this.close() });
works.
,
Sep 5
Cool, thanks!
,
Oct 31
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/4e4c3c10ede11e9ce60c0be6b2b5614831d5a072 commit 4e4c3c10ede11e9ce60c0be6b2b5614831d5a072 Author: Sunny <ratsunny@gmail.com> Date: Wed Oct 31 10:51:52 2018 Postpone listener replacement after non-persistent notification closed When calling |RegisterNonPersistentNotificationListener| with an existed notification id, it will first dispatch a close event to old notification and set new listener into listener map. Currently the new listener is replaced immediately after calling |DispatchNonPersistentCloseEvent|, since it's an asynchronize call, it will remove the replaced listener unexpectedly, instead of removing the original listener. To fix this, we can postpone listener replacement after the close event finish it's cleaning job. For new created notification, the listener can be set immediately due to there is no close event need to be dispatched. Bug: 880266 , 898486 Change-Id: I370d77386cf1a6636f368f1785d92d362a3b4263 Reviewed-on: https://chromium-review.googlesource.com/c/1303898 Reviewed-by: Mike West <mkwst@chromium.org> Commit-Queue: Mike West <mkwst@chromium.org> Cr-Commit-Position: refs/heads/master@{#604203} [modify] https://crrev.com/4e4c3c10ede11e9ce60c0be6b2b5614831d5a072/content/browser/notifications/notification_event_dispatcher_impl.cc [modify] https://crrev.com/4e4c3c10ede11e9ce60c0be6b2b5614831d5a072/content/browser/notifications/notification_event_dispatcher_impl.h [modify] https://crrev.com/4e4c3c10ede11e9ce60c0be6b2b5614831d5a072/content/browser/notifications/notification_event_dispatcher_impl_unittest.cc |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by bm.se...@gmail.com
, Sep 4