Problem with Notifications API of Add-on SDK

I was testing notifications API of the sdk, and found that notification isn’t displayed the first time when I specify an icon to be used with it.

Here’s my sample index.js file:

var notifications = require("sdk/notifications"); var data = require("sdk/self").data; var myiconURL = "./success.png"; notifications.notify({ title: "Done!", text: "It worked.", iconURL: myiconURL });

The icon success.png is placed in data folder, and has dimensions 128x128.

No notification is displayed after I do jpm -b /usr/bin/firefox run. If I remove the iconURL line, it works.

What am I doing wrong here?

EDIT: Dimensions of the icon are irrelevant, since the same thing happens for a 32x32 icon.
Also, note that if I remove the icon specifier, it works as expected.

1 Like

I tested your code in the scratchpad,

I hit Shift + F4 then set “Environment” to Browser from the menu toolbar then ran this code:

// Import SDK Stuff
var COMMONJS_URI = 'resource://gre/modules/commonjs';
var {require} = Cu.import(COMMONJS_URI + '/toolkit/require.js', {});
var notifications = require("sdk/notifications");
var data = require("sdk/self").data;
var myiconURL = "./success.png";
notifications.notify({
    title: "Done!",
    text: "It worked.",
    iconURL: myiconURL
});

This API is flaky, especially on Linux’s and OS X. Try changing the text, add a Math.random() to the end and it will probably work. It’s real quirky, I don’t like it. I avoid it. The other draw back is it only last 4 seconds, if the user is at the computer or not, so its likely the user will miss the notification.

Thanks for your reply!

I gave up an hour later and made the extension display notifications without icons. :grin:

These bugs need to be taken care of though, especially since they’re planning to remove support for XPCOM and XUL based add-ons…

I absolutely agree. This is a very basic API, yet super critical API, and needs also an option/feature to stay till dismissed by user.

Native notifications are flaky on Linux even with the low-level API. libnotify support was dropped, they were implemented in-browser (UGLY!!!), then libnotify support was reintroduced, but it doesn’t always work. I think it is more reliable than the SDK API though, especially on other systems.

Yeah man I gave up with this and with with the browser notification bars -

I just knocked up an api for myself it makes the notification box with react so its real nice and dynamic -

If you install it, it alerts you before each update, its pretty sweet, supports infinite submenus too.

@noitidart - Can include some screenshots (or details on how to include it)? It looks interesting.

Not actually “native” though. This is essentially the solution that Firefox had for Linux (and some Macs) from about version 24 until 35, although with some extra features.

Thanks Amit. I haven’t actually used it yet in my addons, but I plan to soon. I haven’t turned it into a standalone module yet that i can drop in, but as soon as I do that I’ll let you know so including it is a no brainer :slight_smile:

But if you want the non-dynamic/non-transient bar you can go ahead with the regular moz method -