How does one use Chrome desktop notifications? I'd like that use that in my own code.
Update: Here's a blog post explaining webkit notifications with an example.
How does one use Chrome desktop notifications? I'd like that use that in my own code.
Update: Here's a blog post explaining webkit notifications with an example.
I like: http://www.html5rocks.com/en/tutorials/notifications/quick/#toc-examples but it uses old variables, so the demo doesn't work anymore.
webkitNotifications
is nowNotification
.It appears that
window.webkitNotifications
has already been deprecated and removed. However, there's a new API, and it appears to work in the latest version of Firefox as well.codepen
Notify.js is a wrapper around the new webkit notifications. It works pretty well.
http://alxgbsn.co.uk/2013/02/20/notify-js-a-handy-wrapper-for-the-web-notifications-api/
Below is a working example of desktop notifications for Chrome, Firefox, Opera and Safari. Note that for security reasons, starting with Chrome 62, permission for the Notification API may no longer be requested from a cross-origin iframe, so you'll need to save this example in an HTML file on your site/application, and make sure to use HTTPS.
We're using the W3C Notifications API, documented at MDN. Do not confuse this with the Chrome extensions notifications API, which is different. Chrome extension notifications obviously only work in Chrome extensions, don't require any special permission from the user, support rich text notifications, but disappear automatically and the user may not notice they have been triggered). W3C notifications work in many browsers (see support on caniuse), require user permission, stack on top of the previous notification and don't automatically disappear in Chrome (they do in Firefox).
Final words
Notification support has been in continuous flux, with various APIs being deprecated over the last three years. If you're curious, check the previous edits of this answer to see what used to work in Chrome, and to learn the story of rich HTML notifications.
Now the latest standard is at https://notifications.spec.whatwg.org/.
There's also a different call (though with the same parameters) to create notifications from service workers, which for some reason, don't have access to the
Notification()
constructor.See also notify.js for a helper library.
I made this simple Notification wrapper. It works on Chrome, Safari and Firefox.
Probably on Opera, IE and Edge as well but I haven't tested it yet.
Just get the notify.js file from here https://github.com/gravmatt/js-notify and put it into your page.
Get it on Bower
This is how it works:
You have to set the title but the json object as the second argument is optional.