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 badges2 Answers
Reset to default 8Since 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;