alexgibson / notify.js Goto Github PK
View Code? Open in Web Editor NEWA handy wrapper for the Web Notifications API
Home Page: https://alexgibson.github.io/notify.js/
License: Other
A handy wrapper for the Web Notifications API
Home Page: https://alexgibson.github.io/notify.js/
License: Other
Just updated to v1.2.8. Our application does not explicitly call Notify.isSupported() to check if the browser supports web notifications, as we relied on notify.js to do this for us in the past. However, after upgrading to notify.js 1.2.8, calling Notify.requestPermission calls through to window.Notification.requestPermission() which of course throws the error "cannot read property 'requestpermission' of undefined or null."
This may or may not be an issue, depending on where the responsibility lies for determining browser support. I wanted to raise this issue because I'm not sure this was intended behavior, I didn't see anything in the release notes about the responsibility shifting to the implementer of the library.
Any insight would be much appreciated.
Thanks,
-Erik
Hello, you have built a fantastic little script.. well done.
I have found though, This does not work with chrome mobile which is a must. I have tested it with chrome desktop and works great.
Thanks again.
Ben
Self-reminder that I should include an examples folder in master branch with a similar demo to: http://alxgbsn.co.uk/notify.js/
Good day
How do I display a picture or an icon on the notification?
Notification is not shown if multiple tabs are opened in Firefox. It is working fine with Chrome. Have any solutions for that?
I think it might be a good idea to use PageVisibility API to display notifications only when page is not visible for example, like https://github.com/ttsvetko/HTML5-Desktop-Notifications
Notify.config({
pageVisibility: true|false
})
I want to make sure that this is intentional:
https://github.com/alexgibson/notify.js/blob/master/notify.js#L42
Sometimes I want to pass in an empty string for the title, but this check doesn't pass. Is this intentional? If so, I'll pass whitespace.
I think it's unreasonable for a package to require the user to manually install something to be able to use your package.
Your package may depend on jspm if you want but I expect all package to be installable simply with a npm install
.
For instance, all my packages (see this one for instance) are transpiled to ES5 before publishing.
Can you help with code to unsubscribe from notification
yeah basically "Click function won't work if browser or page is not focused"
the notification is just close.
Is this function needs to be simple like window.open or something ?
Hey,
I've updated to 2.0.2 and noticed that it exports differently.
I'm using Babel + CommonJS Module Plugin.
Since 2.0.2 I have to do the following:
import Notify from 'notifyjs';
if (Notify.default.needsPermission) {
Notify.default.requestPermission();
}
Notice the default. - apparently it exports a Object that has a default member as default.
Would it be possible to add url
parameter, which should be opened whenever someone clicks the notification?
Right now it could be done via notifyClick
event, but parameter should make it a little bit easier.
The latest version of requestPermission deprecates the callback interface in favor of a Promise-based interface. This library should support the Promise-based interface as well.
It looks like Safari doesn't currently support the Promise interface, but it should be possible for this library to have its requestPermission
both take a callback and return a promise for backwards compatibility.
Is there a way to trigger something like "notifyClick" for a specific id ?
In my web app users have a checkbox if they want to receive desktop notifications yes or no. If their browser doesn't support notifications to begin with, I don't even want to show this checkbox. However, with the recent changes to isSupported(), I can't do this anymore because it just gives an error:
You must only call this before calling Notification.requestPermission(), otherwise this feature detect would trigger an actual notification!
So how am I supposed to check for support before asking my users if they want notifications?
Trying the notification API on Android, I ran into the following:
http://stackoverflow.com/questions/29774836/failed-to-construct-notification-illegal-constructor
Not sure about iOS support. I was wondering, are there any plans to support mobile browsers through the ServiceWorkerRegistration.showNotification()
API? Especially since the Notification API may be removed in future versions of desktop Chrome.
It seems to me that this library would be a great place to wrap all these different APIs and try to get a solution that works on most devices.
Hi !
First thanks for your lib
Is having a minified version planned ?
Hi ,
below is the website on which i have found your link
https://alxgbsn.co.uk/2013/02/20/notify-js-a-handy-wrapper-for-the-web-notifications-api/
on the above mentioned webiste , when i tested with online demo . It works well on chrome , but then when i download the repo from github , It is not working on chrome.
clicking on notify button it should first shows allow/block notify popup and then after allowing it should start showing notifucation on chrome. Which is not happening.
Please check my attached screenshot , The popup which is coming only when you tested with online demo link , this is not coming after downloading the repo from github. And hence its not working on chrome
At the same time, this one works fine: http://elfoxero.github.io/html5notifications/
Hi Alex ,
Thanks for creating excellent notify.js library .
Unfortunately I am getting issues while trying to use this library sample example on my local machine .
notify.js:32 Uncaught SyntaxError: Unexpected token ...
notify.js:178 Uncaught SyntaxError: Unexpected token export
Also please find attached debug file, which got populated while installing dependencies & build file.
it occures when write
var myNotification = new Notify('Yo dawg!', {
body: 'This is an awesome notification',
notifyShow: onNotifyShow
});
function onNotifyShow() {
console.log('notification was shown!');
}.
it will give notify not define error ("i am not using require here").
and if i use require like:
var Notify = require('notifyjs')
var myNotification = new Notify('Yo dawg!', {
body: 'This is an awesome notification',
notifyShow: onNotifyShow
});
function onNotifyShow() {
console.log('notification was shown!');
}.
then it shows
/Volumes/Project data/node/demo/node_modules/notifyjs/dist/notify.js:63
var N = window.Notification;
^
window is not defined.
please help
The Google Chrome bug mentioned in the README has been fixed as of last month: https://code.google.com/p/chromium/issues/detail?id=274284#c43
Not sure if it's been released yet though
There seems to be a lot of nice updates since the last tag. Namely static isSupported()
type functions. Any chance we can get a new tag soon so bower can pull this package in cleanly?
In any case great job on this package!
Sorry I am new on front-end, I already embed as yours but I want to add link text to notify box. eg:
link .
Currently I see that I can create a static notification:
var myNotification = new Notify('Yo dawg!', {
body: 'This is an awesome notification'
});
and then just invoke it with myNotification.show(). But is there a way to create a notification template and then pass parameters into it? Something like:
var myNotification = new Notify('New messages', {
body: 'You have ' + num + ' new messages'
});
and then myNotification.show({num : 4})
Hi! Great notification abstraction!
Just wondering, any reason for not making the data
attribute available in the Notify
constructor? https://developer.mozilla.org/en-US/docs/Web/API/Notification/data
Edit: Sorry, just saw right now that only Chrome 44 supports this. But still.
Rich Notifications are supported now, can the API also support those?
It would be great to have a lib that works on all browsers and fallback to in-page notifications like http://notifyjs.com/
Do you think this is a good idea?
Uncaught TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.
I just tried to upgrade from v1.3.0 to the latest v2.0.2. But after running $ bower install
, the installation directory no longer contains a notify.js
file (or any other .js
).
I want to push notification via input form for Title, Description and link ( Icon will always be static) - I post and retrieve data from/to xml file
`
TitleThe icon I want to use profile pic and upload it via a script file to set and adjust image so will always be showing profile pic
Then I just want to include a url to click to.
Can you assist or advice me
Thanx
Johan
Please how to add image or icon in the notification
Hey !
I want a notification to popup on a particular day. As I will pack this into an app with electron and it will keep running in the background. Now I need a bit of assistance. The notification doesn't come until I reload the page. So If someone can help me with service worker kind of thing I will be really glad( I'm a noob). Please help me out.
This is the code so far
https://gist.github.com/leovarmak/f98a0ea24cb210c8189e86decffa06b5
I got this error :
Permission has been granted by the user
index.html:42 Error showing notification. You may need to request permission.
O Google Chrome está atualizado
Versão 67.0.3396.99 (Versão oficial) 64 bits
Firefox forces notifications to close after about 4 seconds regardless of the timeout
option. It works fine in Chrome. This note may have something to do with it. Thanks!
Hello,
I'm unable to make your useful library working on Chrome 31 with Windows 7. Here is some code to reproduce the issue : https://gist.github.com/EpocDotFr/7770402
I tested on Firefox 25, works like a charm.
No errors are displayed in the console, I don't know where is the problem :/
I'm building with Grunt and not using ES6 includes with babel or webpack.
Would be handy for the lib to attach to window.Notify if possible
Cheers
On npm install notifyjs
npm will install notifijs 1.2.8 from 2015-10-01
The version of notify.js that gets install seems to be https://github.com/alexgibson/notify.js/blob/62cc926392acd8722997ef66393ac48b2915822a/notify.js
Without the "requireInteraction", "closeOnClick" and "silent" options.
Does the repo need a version bump to 1.2.9 ?
At least your demo page (http://alxgbsn.co.uk/notify.js/) displays notifications fine in desktop and mobile Firefox, as well as in desktop Chrome, but doesn't do anything neither in mobile Chrome, nor in Android default browser. I have tested it on:
(I don't know how to look up the default browser's version).
Please rectify, as I'm really looking forward to using your library. I'd be happy to provide assistance, if need be.
Hi everyone, i am having a little trouble with the timeout
config. I set the timeout to 30s, but when i reload the page that notification doesnt close anymore.
var notification = new Notify('title', {body: 'message', timeout: 30});
notification.show();
Anyone knows how to fix that or just how to clear all Notifications
(which i can use to clear when the page loads)!?
Hey guys,
I am having an issue with notify.js when running unittests out of karma/PhantomJS after updating to to notify.js v1.2.6:
ReferenceError: Can't find variable: Notification at /Users/beane/Code/debug-notify.js/bower_components/notify.js/notify.js:105
This error is thrown before any of my tests run.
Here are my dependency versions:
"devDependencies": { "bower": "1.5.3", "jasmine-core": "2.3.4", "karma": "0.13.10", "karma-jasmine": "0.3.6", "karma-phantomjs-launcher": "0.2.1", "phantomjs": "1.9.18" }
Demo here: https://github.com/ErikBean/debug-notify.js
Any help with this would be great, as our dev team is stuck with the previous version until this gets resolved.
Thanks,
-Erik
I am so confused. Nothing has changed in my code but all of a sudden I cannot receive ANY notifications in chrome. None from any site.
Has anyone experienced this before? What is going on?
As the title says, I didn't get any notification after I confirn them on http://alxgbsn.co.uk/notify.js/ :(
Hi @alexgibson , Can we show comprehensive notification including logo , large text etc. like gmail does ?
Currently only limited text is showing .
Looks like there's some API changes in the latest version of Firefox OS. This is a note to myself to debug, fix & test.
How i can get the click for activate the tab with my Web application??
Is possible do that with your notify.js?
NOTE: Whatsapp has that behavior
Hi,
I have a strange behaviour with Notifications on Firefox. I use the version 45.0.1 both on Debian and Windows.
This code shows up the notification on Windows but not on Debian:
var Notify = require("notifyjs");
var prepareNotification = function () {
var timeoutNotification = new Notify("Inactivité détectée", {
body: "Vous serez déconnecté pour cause d'inactivité dans 60 secondes.",
closeOnClick: true,
timeout: 5,
icon: "http://domain.tld/example.png"
});
timeoutNotification.show();
};
if (!Notify.needsPermission) {
prepareNotification();
} else if (Notify.needsPermission && Notify.isSupported()) {
Notify.requestPermission(function () {
prepareNotification();
});
}
Your demo page works both on Windows and Debian: https://alexgibson.github.io/notify.js/
All is working fine with Chrome.
Thanks for a great library!
It would be very helpful to offer an example of hiding a notification after a few seconds.
My attempt to do
var notification = new Notify(title, {
body: body,
icon: icon,
notifyShow: function(){
setTimeout(function(){
console.log("notify cancel", notification);
console.log("destroy result", notification.destroy());
}, 1000);
}
});
notification.showNotification();
does not hide the notification or cause an error. the code above logs:
notify cancel
Notify {title: "Your Student Loan Rate is About to Go Up", options: Object, permission: null, onShowCallback: function, myNotify: Notification…}
destroy result undefined
Also, I haven't figured out why calling showNotification
works but show
does not.
Thanks so much for any help you can offer!
How to use the script with cron or something else?
maybe you have node.js example
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.