Keep "chrome.notifications.create" alive?!

359 views
Skip to first unread message

Benjamin

unread,
Mar 16, 2017, 8:44:25 AM3/16/17
to Chromium-Extensions-Announce
This is basically what I use:

function myNotification() {
 
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});
 
});
}


I shorten it a bit to just show the important things.
Now this notification pop up, and close after ~12 sec or something.
I just want to KEEP the Notification in my Chrome Extension alive forever.
Until a user interaction happens. Like a click to open the website, or a click to close the notification.

So I can trigger the onClosed AND onClicked events.

Right now I have no chance to figure out if someone clicked on the "X Button" right top corner, to close the Notification.
If the Notification stay alive forever, I can use the "onClosed" to see if someone only press the X to close it.
Or onClicked if someone wants to open the website.

This is important because this defines how long the Notification will not popup again.
Every 5 minutes my extension check for live status. When live notification apears.
When someone click the notification they come to the website. And the extension don't check for 9h for live status anymore.
IF someone click the close button (no fun to see it live today) notification willnot show up for 9h aswell.

At the moment, the Notification disapears after 12 seconds...
And the X close button have NO effect.
So people have to CLICK the Notification (onClicked event triggers) and I can set it to "don't show it for 9h anymore".
That means, people who don't want to visit it right now, HAVE to click (open website) and close website again, so that this Notifcation will not show up again.

Because since the Notification hides after ~12 seconds, I made a midrotation.
Normally check for live status every 5 minutes. If Notification apears, but not clicked (means someone wasn't at the PC, on toilette or something) the Notification comes again after 30 minutes.
So it will show up every 30 minutes... UNTIL a user click (open website) and close webseite again (if no fun to watch)...
And that's not cool. So IF the Notification stays alive forever.
I can do the onClosed and onClicked event.

I tested it that way:

function myNotification() {
 
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});
 
});
  setInterval
(myNotification(), 10000);
}

I just added a:
setInterval(myNotification(), 10000);
at the end of the fun function. So that if the Notification get closed after some seconds, it will spam the notification to keep it alive.
BUT the problem is, it acts like:
Open for 10 sec -> close -> reopen.... -> close -> reopen...
This is not correct aswell. I have totally no idea, how to keep the notification alive.

I really hope for some help! I just don't know what to do anymore.
I saw a Notification on YouTube. It showed me that a channel I abo uploaded a new video. THIS notification kept alive, until I clicked / closed it.
How can YouTube do it?!

PhistucK

unread,
Mar 16, 2017, 10:14:01 AM3/16/17
to Benjamin, Chromium-Extensions-Announce
The documentation mentions requiresInteraction. So -
  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!",
    requiresInteraction: true
  
});


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/9ec7ad45-b51d-4f45-88c4-0502b3500974%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Message has been deleted
Message has been deleted

Benjamin

unread,
Mar 16, 2017, 11:44:21 AM3/16/17
to Chromium-Extensions-Announce, dedr...@googlemail.com
Ok, it seems working with:
requireInteraction

in your code example you had an S in it:
requireSInteraction

I checked the documentation and correct it. Now it seems working.
Now I have to test this with FireFox aswell !
Hope FireFox Addon supports this too :-\
Message has been deleted

PhistucK

unread,
Mar 16, 2017, 12:32:40 PM3/16/17
to Benjamin, Chromium-Extensions-Announce
Sorry for the typo! I am glad this works.
(Regarding Firefox, though, this is not the place. I hope it works out for you)


PhistucK

On Thu, Mar 16, 2017 at 5:55 PM, 'Benjamin' via Chromium-Extensions-Announce <chromium-...@chromium.org> wrote:
It stays open.
But "onClicked" don't close the Notification now. If I click the Notification the new tab opens, thats correct.
But the notification itself stays open. Now I have to figure out how to "close" it manually, ON click :)
Lets check the documentation (did not find anything on the first look).

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
Reply all
Reply to author
Forward
0 new messages