Shahid Thaika
Shahid Thaika

Reputation: 2305

Notification not working in FF Web Extension

I have a browser extension that I coded using WebEx to make it work in Chrome as well as FF/Edge, without porting. The following code works perfectly in Chrome.

toast = function(message, interval) {
    if (!(Notification || !("Notification" in window)))
        return;

    if (Notification.permission !== 'granted') {
        Notification.requestPermission().then(function (permission) {
            if (permission === 'granted') {
                var notification = new Notification('Extension', {
                    icon: chrome.extension.getURL('/img/128.png'), body: message });
                setTimeout(notification.close.bind(notification), interval);
            }
        });
    } else {
        var notification = new Notification('Extension', {
            icon: chrome.extension.getURL('/img/128.png'), body: message });
        setTimeout(notification.close.bind(notification), interval);
    }
}

I know the above is the latest supported code and not the deprecated one as documented here: https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission

FireFox does request permission from me at all. Do anyone have any idea why? Could it be because I am testing it in developer mode and not published?

In debug mode, the browser executes this this line: Notification.requestPermission().then(function (permission) { and then exits normally, but I don't get asked for permission.

Upvotes: 1

Views: 363

Answers (1)

Andrew Swan
Andrew Swan

Reputation: 1343

From an extension, you should use the webextensions notifications api: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/notifications

Upvotes: 1

Related Questions