Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox is not showing desktop notifications if more than one is sent at the same time

I am trying to implement desktop notifications for my application. It works fine if one notification is sent, however when more than one is sent at the same time, firefox does not display any of them. This problem is not present with Chrome.

Is this something that is just not possible with firefox? I was under the impression that the usage of tags inside the notification options were used for stacking notifications.

Code:

function isNewNotificationSupported() {
  if (!window.Notification || !Notification.requestPermission) return false;
  if (Notification.permission == "granted") throw new Error("");
  try {
    new Notification("");
  } catch (e) {
    if (e.name == "TypeError") return false;
  }
  return true;
}

function notifyMe(aa, bb, cc, dd) {
  if (!("Notification" in window)) {
    //alert("This browser does not support desktop notification");
  } else if (Notification.permission === "granted") {
    if (!document.hasFocus() || cc == 1) {
      var options = {
        body: bb,
        icon: "",
        dir: "ltr",
        tag: dd
      };
      var notification = new Notification(aa, options);

      notification.onshow = function() {
        setTimeout(notification.close.bind(notification), 15000);
      };
    }
  } else if (Notification.permission !== "denied") {
    if (isNewNotificationSupported()) {
      Notification.requestPermission(function(permission) {
        if (!("permission" in Notification)) {
          Notification.permission = permission;
        }

        if (permission === "granted") {
          var options = {
            body: bb,
            icon: "",
            dir: "ltr",
            tag: dd
          };
          var notification = new Notification(aa, options);

          notification.onshow = function() {
            setTimeout(notification.close.bind(notification), 15000);
          };
        }
      });
    }
  }
}

notifyMe("New notification1","newtest","1","test1");
notifyMe("New notification2","newtest2","1","test2");

I created a jsfiddle for it at:

http://jsfiddle.net/1bm0wyvf/

Update: I think i solved it now by changing one of the notifyMe's to:

setTimeout(function() { notifyMe("Newnotification1","newtest","1","test1"); }, 200);

Firefox properly stacks them now.

like image 556
Sempiterna Avatar asked May 26 '15 14:05

Sempiterna


People also ask

How do I manage notifications in Firefox?

Go to the browser menu and select "Settings." On the left, click on "Privacy & Security." Scroll down to the "Permissions" window, and select "Notification." If you want to disable notifications, check "Pause notifications until Firefox restarts." Thus, notifications will not appear until you restart Firefox.

How do I add notification sounds to Firefox?

The default Firefox notification system doesn't notify you with audio, only visually. This extensions adds sounds to some notifications. Choose if which websites and supported extensions you want a sound to be played for. You can both work on an include or exclude principle.


1 Answers

I am using the following function and it behave very well on Firefox/Linux.

function notif(message){

 if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {
      if (!('permission' in Notification)) {
        Notification.permission = permission
      }
      if (permission === "granted") {
          let notification = new Notification(message)
      }
    })
  }
}
notif("Hello world!!")

enter image description here

like image 94
NVRM Avatar answered Oct 16 '22 19:10

NVRM