Patrick Mlr
Patrick Mlr

Reputation: 2965

Mozilla WebExtension desktop notification display time and/or require user interaction

I have a WebExtension for Mozilla, which notifies me with the desktop notification function.

It works exactly how I want, but Firefox will close the notification automatically after X seconds. Is it possible to display the notification until the user clicks on it?

The thing I did is to close and reopen the notification every 5 seconds, so the user has to click on it to close it permanently.

This looks like this:

// This is the notification function
function notifyMeFunction() {    
    var notification = new Notification('Alert', {
        icon: chrome.extension.getURL('icons.png'),
        body: "New Notification",
        tag: "DesktopNotification",
    });


    notification.onclick = function(event) {
        notificationClicked = true;
    }

    notification.onclose = function(event) {
        notificationClicked = true;
    }
}

// Function which will self-open every 5 seconds
function notifyMe() {
    if (notificationClicked == false) {
        notifyMeFunction();
        setTimeout(notifyMe, 5000);
    } else {
       notificationClicked = false;
    }
}

Any ideas how to set the display time to something like "must interact"?

Upvotes: 0

Views: 414

Answers (1)

Makyen
Makyen

Reputation: 33306

There is, currently (Firefox version <= 51.0a1), no method of indicating to the API that the user must interact with these notifications. Nor is there any way to specify for how long the notification is displayed to the user.

Note: You are using the Web Notifications API, not the WebExtensions chrome.notifications API. Neither has a way to require user interacting in Firefox.

From Chrome 50, Google Chrome does have an option to require that the user must interact with the notification: requireInteraction. Thus, at some point in time, Firefox will probably support such an option.

However, at least as of this point in time, the string requireInteraction does not exist in the Firefox source code.

Upvotes: 2

Related Questions