Reputation: 29331
I have a Google Chrome extension in production. One part of the program displays notifications through the chrome.notifications API. I begin displaying notifications with this logic:
// Expects options: { iconUrl: string, title: string, message: string }
showNotification: function (options) {
// TODO: Future version of Google Chrome will support permission levels on notifications.
if (chrome.notifications.getPermissionLevel) {
chrome.notifications.getPermissionLevel(function (permissionLevel) {
if (permissionLevel === 'granted') {
doShowNotification(options);
}
});
} else {
doShowNotification(options);
}
}
This logic works fine. The getPermissionLevel function hasn't been implemented yet, but will be in the future. So, I check to see if it has been implemented and, if not, simply show the notification.
I'm seeing an error thrown on some clients. The error message states that chrome.notifications is undefined on the following line:
if (chrome.notifications.getPermissionLevel) {
with error message:
Uncaught TypeError: Cannot read property 'getPermissionLevel' of undefined
This is odd because this code works perfectly fine for me, my test cases pass, etc. Additionally, I have the following rule in my manifest.json:
"minimum_chrome_version": "29.0.1547.76"
This should force all clients to use a version of Google Chrome which supports notifications. According to the docs, http://developer.chrome.com/extensions/notifications.html, notifications went stable in Chrome 28:
Availability: Stable since Chrome 28.
In addition, I have the following permissions declared:
"permissions": [
"contextMenus",
"management",
"notifications",
"storage",
"identity",
"webRequest",
"webRequestBlocking"
]
I'm requesting the notifications privilege and am ensuring that users are using a current browser version.
Does anyone know any other reasons chrome.notifications would be undefined? I know that I can simple ensure it is defined, but I would like to know what is going on. Thanks.
Upvotes: 2
Views: 1836
Reputation: 48211
The only reason I can think of is the API's not being supported in Linux.
According to the docs:
Note: This API is currently available on ChromeOS, Windows, and Mac.
I haven't tried with the latest version, but I know there where issues on Linux with previous Chrome versions (e.g. no buttons where displayed etc).
I am not sure if it currently affects different distributions differently. In any case it would be a good idea to check the Chrome version and OS of the failing clients.
Upvotes: 2