简体   繁体   中英

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.

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!!")

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM