MozillaZine

Windows Notification in FireFox Addon

Talk about add-ons and extension development.
homezonebenny
 
Posts: 5
Joined: February 10th, 2017, 6:33 am

Post Posted February 10th, 2017, 7:05 am

I created this:

Code: Select all
// Nofitication Function
function myNotification(channelName, title) {
  var notification = browser.notifications.create("online_status",{
    "type": "basic",
    "iconUrl": browser.extension.getURL("icons/64.png"),
    "title": title,
    "message": "Click this message to visit the website!\nTell your friends about " + nickname + " ;-)",
    "eventTime": 32400000
  });

  browser.notifications.onClicked.addListener(function() {
    time = bigRotation;                                                         // increase check time
    localStorage.TIME = bigRotation;
    browser.tabs.create({"url": "http://www.url.com/" + channelName});
  });

  browser.notifications.onButtonClicked.addListener(function() {
    time = bigRotation;                                                         // increase check time
    localStorage.TIME = bigRotation;
  });
}
//------------------------------------------------------------------------------


Now I have some problems with it.

1. Problem: eventTime
The event time should keep the Notification alive for 9h.
I tested it with 1, 2, 5 minutes aswell. Wont work. It's close after ~10-15 sec...

2. Problem: onButtonClicked
I try to get the X (close) button clicked (right top corner of a Notification).
When a user close the Notification with the X-Symbol, it ads a 9h rotation time.
So that the Notification will not apear again in the next 9h.
The same for a click ON the Notification. If someone click the Notification a new browser tab is opened.
And the delay is set to 9h aswell.
I tried the onClosed() method. But this happens also when the Notification disapears without any user interaction (click).
So I can't use onClosed().
But onButtonClicked() seems only working with a custom button or something.

Here are the resources:
I could use the onClosed() Method instead of onButtonClicked IF I can keep the Notification alive forever (eventTime).

Thanks for your help! <3 :)
Last edited by homezonebenny on February 10th, 2017, 11:28 am, edited 5 times in total.

DanRaisch
Moderator

User avatar
 
Posts: 116105
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted February 10th, 2017, 7:22 am

Moving to Extension Development.

morat
 
Posts: 2261
Joined: February 3rd, 2009, 6:29 pm

Post Posted February 10th, 2017, 10:24 pm

Isn't the eventTime value too small?

e.g. Date.now() + positive integer

NotificationOptions
http://developer.chrome.com/extensions/ ... ionOptions

homezonebenny
 
Posts: 5
Joined: February 10th, 2017, 6:33 am

Post Posted February 11th, 2017, 1:27 am

@morat:
I figured that out with Date.now() but the problem is, it's not supported in firefox...
https://developer.mozilla.org/en-US/Add ... ionOptions
Scroll down to the end of the document:

Compatibility notes
Firefox
Only 'type', 'iconUrl', 'title', and 'message' are supported.

So eventTime will not work in FireFox.
And here:
https://developer.mozilla.org/en-US/Add ... tonClicked
it's not supported in FireFox aswell... This is available since v45 im at v51 right now. Still not supported.
I can't understand that.

Do you know a way to report that to FireFox developers?!
I mean, why is this stuff still not fully working for FireFox. Don't get it...

morat
 
Posts: 2261
Joined: February 3rd, 2009, 6:29 pm

Post Posted February 11th, 2017, 7:54 am

Mozilla says the chrome.notifications.create() API is supported, but only 4 of 14 properties are supported.

Are we WebExtensions yet? notifications
http://arewewebextensionsyet.com/#notifications

People are assuming that many Chrome extensions will be available to Firefox 57 users. Not likely.

Old Firefox Add-Ons Will Stop Working in Firefox 57
http://www.bleepingcomputer.com/news/so ... d-of-2017/

morat
 
Posts: 2261
Joined: February 3rd, 2009, 6:29 pm

Post Posted February 11th, 2017, 10:47 am

Is the type property supported? AFAICT, Mozilla only supports iconUrl, title and message properties in Firefox 54.

ext-notifications.js
http://dxr.mozilla.org/mozilla-central/ ... cations.js

I guess Mozilla will eventually support all the properties in the notifications schema since they want parity with Chrome.

notifications.json (missing the requireInteraction property)
http://dxr.mozilla.org/mozilla-central/ ... tions.json

Edit:

morat wrote:Is the type property supported?

Mozilla only supports the basic type.

TemplateType
http://developer.mozilla.org/en-US/Add- ... mplateType
Last edited by morat on February 12th, 2017, 4:45 am, edited 1 time in total.

homezonebenny
 
Posts: 5
Joined: February 10th, 2017, 6:33 am

Post Posted February 11th, 2017, 11:05 am

So basically I have to wait a while until:
- eventTime
- onButtonClicked
is supported in FireFox.

I'll put the new scripts into my Chrome Plugin and making it work in Chrome.
When everything runs well in Chrome, it will run well in a newer FireFox Version! :)

morat
 
Posts: 2261
Joined: February 3rd, 2009, 6:29 pm

Post Posted February 12th, 2017, 6:56 am

Hopefully all you need to do is wait a while, but I could be wrong.

Bob Silverberg wrote:There are options in NotificationOptions that we will never support.

Bob Silverberg wrote:It may be that the onButtonClicked event remains unsupported for the first release of web extensions, but is something we endeavor to support in the future.

Bug 1254291: Add schema for the notifications API, Comment 3
http://bugzilla.mozilla.org/show_bug.cgi?id=1254291#c3

Bug 1213455: Complete the implementation of chrome.notifications, Comment 6
http://bugzilla.mozilla.org/show_bug.cgi?id=1213455#c6

The onButtonClicked event does not apply to the nsIAlertsService.

nsIAlertsService
http://developer.mozilla.org/en-US/docs ... rtsService

homezonebenny
 
Posts: 5
Joined: February 10th, 2017, 6:33 am

Post Posted February 13th, 2017, 2:20 am

Do you know why eventTime isn't working in Chrome either?!

Code: Select all
  var notification = chrome.notifications.create("online_status",{
    "type": "basic",
    "iconUrl": chrome.extension.getURL("icons/64.png"),
    "title": title,
    "message": "text",
    "eventTime": Date.now() + 32400000
  });


Normally this should hold the notification for like 9h...


And I tried this:

Code: Select all
  chrome.notifications.onButtonClicked.addListener(function() {
    alert('closed');
  });

To see if someone clicked on the X (close) Icon of the notification.
Alert is working in chrome. In Firefox you have to use console.log('closed');

homezonebenny
 
Posts: 5
Joined: February 10th, 2017, 6:33 am

Post Posted March 13th, 2017, 1:09 pm

Someone knows how I can keep the Notification alive unlimited?!

I saw a YouTube Notification a day ago, and this notification kept alive forever.
Until I closed / clicked (open link) it manually.
That's exactly what I want. Then I can use the onClose event right (with the X close button).

This is basically the code I use (made it a bit shorter for better overview):

Code: Select all
function myNotification(channelName, title) {
  var notification = browser.notifications.create("online_status",{
    "type": "basic",
    "iconUrl": browser.extension.getURL("icons/64.png"),
    "title": title,
    "message": "Click this message to visit the website!"
  });

  browser.notifications.onClicked.addListener(function() {
    browser.tabs.create({"url": "http://www.url.com/" + channelName});
  });
}


Now I really have to figure out, how to keep this notification alive unlimited.
Until a user interaction (manually closed / clicked by user).

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests