Reputation: 41
In my code, the contextMessage is not showing up
I know it works fine with chrome.notifications.create
, but if I use that then I can't make it so the notification never disappears without being closed or clicked on
function Notify(Title, Body, miniMsg, Url, Icon) {
var notification = new Notification(Title, {
icon: Icon||"Logo.png",
body: Body,
contextMessage:miniMsg
});
notification.onclick = function () {
window.open(Url);
}
}
Thanks!
Upvotes: 0
Views: 203
Reputation: 1642
The answer is simple: Compatibility.
You are trying to use a feature that isn't supported in Chrome without the webkit
prefix, according to MDN. For a Google Chrome extension, it is suggested to use the chrome.notifications
API.
Using the chrome.notifications
API, you are unable to specify how long the notifications stay open. However, another option is to use the chrome.experimental.notifications
API, which would prevent you from publishing your extension to the webstore, and has very little documentation.
You could also change the priority
option in chrome.notifications.create
to any integer between -2 to 2, where 2 is the highest, and would grant your notification the most display time.
Since you seem to be using the Notifications
object, you might notice that your syntax does not match that shown in the MDN documentation. Primarily, there does not seem to be any contextMessage
parameter for Notifications. As a side note, the onclick
callback won't work, since the Url
parameter is no longer executed in the current scope. The anonymous function will not be able to see the Url
parameter passed into Notify
. You also might want to check out compatibility and notes for Notifications.
Upvotes: 2