I have an chrome-extension that i want to use the new rich notifications. I'm trying to implement the following:
var opt = {
type: "basic",
title: "New message from " + sBuffer[0] + ":",
message: sBuffer[2],
iconUrl: getUserIcon(sBuffer[0])
};
chrome.notifications.create("",opt,function(){});
But no matter what i do, i get the following error:
Uncaught TypeError: Cannot call method 'create' of undefined
I went into chrome://flags
and set everything with 'notifications' in it to enabled... I'm running chrome 31.0.1650.57 m.
This works fine:
var notification = webkitNotifications.createNotification(
getUserIcon(sBuffer[0]),
"New message from " + sBuffer[0] + ":",
sBuffer[2]
);
notification.show();
It's not pretty, but it works (the icon is tiny even though it's a high-res image... Is there any way i can make the image icon bigger?)
BTW, i've got the notifications permission in my manifest.
Thanks,Dave
EDIT: Included manifest
{
"manifest_version": 2,
"name": "Notifier",
"description": "This extension will listen the the JS on the page and popup notifications",
"version": "0.1",
"permissions": [
"background","notifications"
],
"content_scripts": [
{
"matches": ["http://MY_WEB_SITE"],
"js": ["Notifier.js"]
}
]
}
Use the chrome. notifications API to create rich notifications using templates and show these notifications to users in the system tray. This permission triggers a warning.
Frequently asked questions Use the chrome.notifications API to create rich notifications using templates and show these notifications to users in the system tray. Button icons not visible for Mac OS X users. Additional details about this item. Title of one item of a list notification. The app icon mask is not visible for Mac OS X users.
On Chrome OS, notifications show up in a user's system tray, and stay in the system tray until the user dismisses them. The system tray keeps a count of all new notifications. Once a users sees the notifications in the system tray, the count is reset to zero.
Closing and relaunching Chrome could also help eliminate glitches that prevent websites from delivering notifications to your computer. Try that and see if it helps. If you still don't get website notifications on Chrome, despite trying all the solutions recommended above, you might want to reset Chrome's settings.
Instead of Chrome's own notifications, users see native Mac OS X notifications. Learn more in this article. The rich notifications API lets you create notifications using templates and show these notifications to users in the user's system tray: Rich notifications come in four different flavors: basic, image, list, and progress.
It seems like you are trying to access the chrome.notifications
API from a content script. But it is not available for content scripts, so you'll need to create the notification in the background page.
If you need to pass specific data to be displayed in the notification, you can use Message Passing to communicate between the content script and the background page.
E.g.:
/* In content script */
chrome.runtime.sendMessage({
from: sBuffer[0],
body: sBuffer[2]
});
/* In background page */
chrome.runtime.onMessage.addListener(function(msg, sender) {
/* Verify the message's format */
(msg.from !== undefined) || return;
(msg.body !== undefined) || return;
/* Create and show the notification */
// ...your notification creation code goes here
// (replace `sBuffer[0]`/`sBuffer[2]` with `msg.from`/`msg.body`)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With