Reputation: 1914
I wanted to try and use the chrome.notifications
api on Chrome (using Windows and Chrome 40+, so the API is supported). The only problem is that the object simply does not exist when trying to use. The type of chrome.notifications
is undefined, and obviously if I try to use chrome.notifications.create
, I get an error "cannot read property create of undefined".
The thing is, I have activated notifications, and I'm using pushbullet with my android phone, which uses this rich notifications feature, and it works perfectly.
So is chrome.notifications
reserved for chrome apps?
Thanks you very much.
Upvotes: 3
Views: 821
Reputation: 47099
I think chrome.notifications
is chrome plugin only, but you can use the "standard" Notification
api
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother them any more.
}
This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.
Upvotes: 2