1

I'm writing a Chrome extension that reminds the user of something every X minutes, using event pages, alarms, and the Chrome extensions notifications API.

The problem is that if the user lets the notification window disappear (it's on screen for only ~10 seconds), it will never be displayed again. This seems like a bug in Chrome, but wanted to check if maybe I'm missing something.

chrome.alarms.create('remindUser', {
  delayInMinutes: 1,
  periodInMinutes: 5
});

chrome.alarms.onAlarm.addListener(function (alarm) {
  chrome.notifications.create(alarm.name, {
    type: 'basic',
    title: 'Reminder',
    message: '...',
    buttons: [
      { title: 'Act on it' },
      { title: 'Later' }
    ]
  }, function callback(notificationId) {
    // nothing necessary here, but required before Chrome 42
    console.log(notificationId, 'notifications ARE called repeatedly, but the window is not displayed');
  });
});

Nothing special in manifest.json:

"permissions": ["alarms", "notifications", "storage", "contextMenus"]

If I click on the x button to close the notification, it will be displayed next time. But if I'm away from the computer and don't do anything when the notification shows up, it will never be displayed again. The console shows the remindUser notifications ARE called repeatedly [...] message with an increasing count, but the notification is not displayed again.

How can this be fixed? I'd rather not use the Notification API because it bugs the user for permission.

Community
  • 1
  • 1
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • I wonder if this could be a restriction added by Google, to prevent applications from repeatedly annoying the user (similar to "prevent this page from creating additional dialogs"). – johnnyRose May 29 '15 at 00:26
  • 1
    @Johnny_Rose: [alarms are already limited](https://developer.chrome.com/extensions/alarms) to at most once per minute. I think it's an oversight similar to the [Firefox bug](https://bugzilla.mozilla.org/show_bug.cgi?id=875114). I filed a [Chromium bug](https://code.google.com/p/chromium/issues/detail?id=493500). – Dan Dascalescu May 29 '15 at 01:34

1 Answers1

1

The reason this happens is that the notifications always have the same ID, alarm.name. This causes subsequent notifications to replace previous ones as indicated at https://developer.chrome.com/extensions/notifications#method-create

After removing the ID from the chrome.notifications.create call, all notifications are displayed. There is still the issue that they'll be hidden under Chrome's bell icon in the system tray though, while notifications generated with the Notification API never disappear:

enter image description here

Not sure what the reason is for the inconsistency between the two notification APIs in how persistence/docking into the system tray are handled, so I filed a bug with Chromium.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • 1
    This is expected; bug will probably be closed as Wontfix. From the ground up Chrome notifications are designed not to stay on the screen for too long. Do note, there is a hacky way to bypass this - if your update changes priority, it will be re-shown. See [here](http://stackoverflow.com/a/26358154/934239). – Xan May 29 '15 at 09:59
  • @Xan - you can trivially create notifications that stay on the screen indefinitely by using [the Notification API](http://stackoverflow.com/questions/2271156/chrome-desktop-notification-example/13328513#13328513). – Dan Dascalescu May 31 '15 at 00:07
  • I know, and I know you know it. I'm talking specifically about Rich Notifications. – Xan May 31 '15 at 00:22