electron: [Bug]: notification.close() does not work in Windows after the popup has disappeared

Preflight Checklist

Electron Version

16.0.4

What operating system are you using?

Windows

Operating System Version

Windows 11 21H2 22000.376

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Repro:

  1. Create a notification in the renderer process with the HTML5 notification API
  2. Wait for the notification popup to disappear and be logged to the Windows notification center
  3. Call notification.close() on it

The notification is removed from the Windows notification center and the “unread” count in the taskbar decreases

Actual Behavior

The notification remains in the Windows notification center and the unread count does not change.

Testcase Gist URL

https://gist.github.com/eeba5a0f434736fe3a58966e74fce37d

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Out of sight, out of mind, eh? An issue become not an issue if you wait long enough?

As a work around I’m adding 6 sec delay and forcibly close the notification: in main process

notification.on('show', e => setTimeout(notification.close.bind(notification), 6000));

or in renderer:

notification.addEventListener("show", e => setTimeout(notification.close.bind(notification), 6000));

(only tested on Windows 10)

P.S. Electron v20.0.0-nightly.20220330 still affected.

Windows 11 also affected. The last working version was v11.5.0; Starting with v12.0.0beta1 the notifications become “persistent”.

In addition, clicking at the notification in the notification center clears the notification, however onclick event never fired/received and after reopening notification center the notification shown again. The only way get rid of it is to click x

The issue affects both native HTML5 notifications and electron’s Notification

There are two sides:

  1. Being able to programmatically remove the notification from the action center. That’s what the guide covers. That’s was the most important in my use case, and is what this issue is about.
  2. Detecting when the user decides to manually clear a notification from the action center. To have full notification syncing you’d ideally want this as well, so you can clear notifications from other devices when this happens. But it’s a lot more rare for users to go digging in here to clear things out, and doing this is a lot harder.

I won’t be trying to figure out part 2 here; I’m currently focusing on migrating to Tauri.

Hi, is there any plan to fix this issue? Or, somebody know any alternative plan?

I wonder if this bug related to bundled chromium version and not electron itself?

Do you have any plan to resolve the issue?

Looking at the spec more closely: https://notifications.spec.whatwg.org/#lifetime-and-ui-integrations

The user agent must keep a list of notifications, which is a list of zero or more notifications.

User agents should run the close steps for a non-persistent notification a couple of seconds after they have been created.

User agents should not display non-persistent notification in a platform’s “notification center” (if available).

User agents should persist persistent notifications until they are removed from the list of notifications.

A persistent notification could have the close() method invoked of one of its Notification objects.

User agents should display persistent notifications in a platform’s “notification center” (if available).

It seems like right now Electron is doing a cross between persistent and non-persistent here. It is firing the close event on the notification as soon as the popup disappears but is leaving an entry in the notification center as a piece of trash if the user doesn’t get to it right away.