最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome extension notification shows only once - Stack Overflow

programmeradmin9浏览0评论

My goal is to create a notification with a Chrome extension when a value in firebase changes.
With the code below I receive a notification the first time I'm changing the value, but not the following times.

f.on('child_changed', function (snapshot) {
  ignoreInitialData = false;
  var options = {
    type: 'basic',
    iconUrl: '../../icons/green.png',
    title: "Availability notifier",
    message: snapshot.val(),
    contextMessage: "",
    eventTime: Date.now(),
    isClickable: false,
  };
  chrome.notifications.create("child_changed", options, function (notificationID) {
    console.error(chrome.runtime.lastError);
  });
});

Any solutions?

My goal is to create a notification with a Chrome extension when a value in firebase changes.
With the code below I receive a notification the first time I'm changing the value, but not the following times.

f.on('child_changed', function (snapshot) {
  ignoreInitialData = false;
  var options = {
    type: 'basic',
    iconUrl: '../../icons/green.png',
    title: "Availability notifier",
    message: snapshot.val(),
    contextMessage: "",
    eventTime: Date.now(),
    isClickable: false,
  };
  chrome.notifications.create("child_changed", options, function (notificationID) {
    console.error(chrome.runtime.lastError);
  });
});

Any solutions?

Share Improve this question edited Dec 5, 2014 at 15:27 Xan 77.7k18 gold badges197 silver badges217 bronze badges asked Dec 5, 2014 at 11:50 Dallari GianlucaDallari Gianluca 311 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Since you're using a fixed notification ID, it's updated instead of creating a new one.

If the notification is not closed but hidden in the Chrome notification center, it will not be shown again.

Your options include:

  • Not using a fixed ID (pass "" as ID)
    This will cause both the old and the new notifications to remain until dismissed. Probably not what you want.

  • Closing the old notification just before showing a new one.
    This works well, but is visually jarring if your old notification did not yet disappear. However, you may actually want this effect if you want to emphasize "this is new information"

  • Using a priority change trick to re-show the notification.
    This works best, but is "hacky". We can only hope Chrome API will improve to do this natively.

You can also add a timestamp suffix so every notification is different:

var timestamp = new Date().getTime();
var id = 'myid' + timestamp;
发布评论

评论列表(0)

  1. 暂无评论