Greasemonkey: Add GM_notification API

Created on 20 Sep 2010  ·  26Comments  ·  Source: greasemonkey/greasemonkey

As a user script author I would love to be able to send clickable notifications to my users instead of alert on confirmation windows in many situations.

Most helpful comment

All 26 comments

using the patch from #1193 this is a piece of cake, the clickable part is a little extra work tho.

note: @icon from #1096 could be used for the icon of the notification.

Would be nice to have it outside of the unprivileged DOM sometimes... but consensus on what kind of notification may be an issue.

The phrase "send notifications" is extremely vague.

Assuming that you intend this to mean "provide an interface to nsIAlertsService" I'd have to think a while before I could form a clear opinion. In general, I really dislike the toast notifications that (I assume) this provides. They appear to be extremely brief and difficult to interact with. Almost every time (e.g.) either Firefox or Thunderbird tells me there's an update or a new message, the toast has disappeared almost before I've had time to stop what I'm doing, read the box, and figure out what it says.

I think my gut reaction would be that this should be an @require that puts it in the DOM of _that_ page, otherwise how is the user supposed to know which page the message is coming from (especially when there could be multiple appropriate tabs open)?

Assuming that you intend this to mean "provide an interface to nsIAlertsService"

Yes this is would use what I implemented in #1193

the toast has disappeared almost before I've had time to stop what I'm doing, read the box, and figure out what it says.

Well I love them, and I think it's better for a user script author to decide if it's useful to their script or not. Besides I think how long they appear is a customizable setting, at least w/ osx I know it is.

I think my gut reaction would be that this should be an @require that puts it in the DOM of that page,

how would that be done..?

how is the user supposed to know which page the message is coming from (especially when there could be multiple appropriate tabs open)?

the title can be the name of the user script, and the icon could be it's @icon.

They appear to be extremely brief and difficult to interact with. Almost every time (e.g.) either Firefox or Thunderbird tells me there's an update or a new message, the toast has disappeared almost before I've had time to stop what I'm doing, read the box, and figure out what it says.

alerts.totalOpenTime is the setting that you want to change, the default value is 4secs, I usually like 30secs.

Would you be willing to add custom image support?

function GM_notification(aMsg, aTitle, aImg) {
  var title = aTitle ? "" + aTitle : "Greasemonkey";
  var message = aMsg ? "" + aMsg : "";
  var image = aImg ? "" + aImg : "chrome://greasemonkey/skin/icon_medium.png";
  try {
    alertsServ.showAlertNotification(
        image,
        title, message, false, "", null);
        //This looks better on ubuntu than windows ( http://i55.tinypic.com/2jfwtg9.png )
  } catch (e) {
    // In case e.g. Growl is not installed on a Mac.
    alert(title + "\n" + message);
  }
};

Duped by #1271

voting wontfix on this

voting wontfix for this

Why?

arantius wrote:
The point is that the feature it replaced depended on the status bar, which is going away in Firefox 4. It is, currently, no more than that.

This feature would be helpful for scripts that redirect the DOM multiple times and eventually land on an image instead of a htm/l and still allow notifications to the end user that a certain detail has occurred. As we all know user.js only works on .htm/l files not images.

Voting +1 to expose the API function to the sandbox as it is very simple to do with additional benefits.

EDIT: To address the request from GM-Script-Writer-62850 the value at @icon could easily be used in conjunction with this.

+1

Firefox 22 has web notifications support: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/22

But I think it has a major mistake (https://bugzilla.mozilla.org/show_bug.cgi?id=875114, respectively https://bugzilla.mozilla.org/show_bug.cgi?id=862395). Then I can close: https://github.com/greasemonkey/greasemonkey/issues/1742

In some use cases we might be able to use web notifications instead, which can be added to Firefox using various addons like tab notifier.

In some use cases we might be able to use web notifications instead, which can be added to Firefox using various addons like tab notifier.

But by using web notification api, script can only pop up notifications if user allow the site to do so. User have no choice to disable notifications from the website but enable it from script.

Right, I totally missed that aspect. :+1:
A work-around could be to use a secret password and configure tab notifier to only show notifications that include it. Depending on the evilness of the site, a single strange unicode character might be enough, could even be an invisible one.

Again, this API is needed since the website begin to show notifications which user want to block them. But I need to show notifications too. As the result, user have no chose between disable all these notifications or enable all of them. I need this API so that user may only allow notifications from the userscript.

The testing branch:
https://github.com/janekptacijarabaci/greasemonkey/tree/_testBranch_GM_notification

Synchronize API with Tampermonkey
See also https://tampermonkey.net/documentation.php#GM_notification

This is just a thing for testing! (using the eval() function, etc.)

Uses the function "PopupNotifications" (!= "Web (HTML5) Notification API")!
(I don't need this feature - for now I'll wait to solve this problem: bug 862395)

@janekptacijarabaci Thanks, but I found it is buggy...

  1. PopupNotifications.jsm is not Desktop Notification: The notification will not be shown if the browser window is minimized. (Yes, this is very important otherwise it become much more useless)
  2. onclick and ondone should be optional, but currently it will fail without these values

(I'm not sure when bug 862395 will be fixed. But I think it is better to have a buggy but usable one than nothing.)

Test branch updated:
Popup Notifications => Desktop Notification

@janekptacijarabaci
Thank you.

To my understanding, currently implementation in the test branch only allow notification when user grant permission to the site to do so. It just like calling Notification directly. User still have no choice to disable notification from the site but allow it to userscript.

I am not sure what you do consider this api should be. But I hope this one may work with different permission control to content scripts from the website. (And that is TM currently do. They always allow userscript show notifications)

@tiansh

The question is how to do it...

The Desktop Notification in Chrome (Tampermonkey) is different:
https://developer.chrome.com/extensions/desktop_notifications

System principal (chrome-privileged) should be granted permission. But...
Using message-passing (especially under e10s on) - kills all events (onclick, ondone).
This function may be used as follows:
https://github.com/greasemonkey/greasemonkey/blob/3.9/modules/sandbox.js#L75
(https://github.com/greasemonkey/greasemonkey/blob/3.9/modules/menucommand.js#L90)
but I leave it to the community/arantius (I'm not sure about the way how to do it best).
(I don't know if someone wants to do this: #2275 - http://arewewebextensionsyet.com/#notifications)

I don't have a better idea now...

However I have made some attempt...

Edited:
But... Run GM_notification() twice (and more) in a row does not work for me.

See also bug 1263155 (1294332, 1306822)...

So... Was it implemented or not?

@VBelozyorov , I don't think it was implemented for 3.x. But for 4.x #2590

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JasonBarnabe picture JasonBarnabe  ·  18Comments

Rick-74 picture Rick-74  ·  29Comments

arantius picture arantius  ·  48Comments

GuardianMajor picture GuardianMajor  ·  11Comments

an-electric-sheep picture an-electric-sheep  ·  11Comments