Search code examples
google-chrome-extensionchrome-extension-manifest-v3

what's the purpose of eventTime in NotificationOptions of chrome.notifications API?


When creating a notification from an extension using chrome.notifications API, the NotificationOptions: eventTime seems to be ignored as the notification is created immediately which supposed to be delayed by milliseconds set for eventTime. As per documentation:

eventTime
A timestamp associated with the notification, in milliseconds past the epoch (e.g. Date.now() + n).

Although this is not clearly stated that this will cause a delay in creation of the notification by the milliseconds set in eventTime, then what's the purpose of this option?


I found a similar question was asked some years ago: Chrome notification ignoring eventTime but the above question was not answered there. Instead the solution was talking about the other approaches (setTimeout, chrome.alarms) to delay the creation of notification.


Solution

  • According to the source code, eventTime does not delay the notification.

    • It's displayed in the title of the notification (source).

      For example, setting it to Date.now() + (5 * 60 + 1) * 1000 shows In 5m i.e. five minutes.

      enter image description here

      Note that we had to add one second, otherwise the API shows 4m as it subtracts the few microseconds spent in creating the notification internally.

    • It's used to sort notifications within the same priority group (source)