Reputation: 77
This verifies whether the page is https and whether a localStorage item evaluates to true or false, and displays a notification based on that. The code is placed in the popup.js:
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function(array_of_Tabs) {
var tab = array_of_Tabs[0];
var url = tab.url;
if (url.indexOf('https:') === 0 && localStorage.getItem("secureRead").value !== true) {
chrome.extension.getBackgroundPage().showNotify();
}
});
The actual notification code is placed in the background.js file:
var notification = webkitNotifications.createNotification(
'icon48.png',
'Secure page detected.',
'Checking "Enable HTTPS reading" in the setting is required.'
);
function showNotify()
{
notification.show();
}
The problem is that this only works once, globally. No other page is then detected, evaluated and no notification is shown. What am I doing wrong?
There are no errors thrown at me either.
Upvotes: 0
Views: 462
Reputation: 14502
First, you should be aware that the current notification system (i.e. webkitNotifications.createNotification) is deprecated, and has been removed from Chrome, at least on Windows and ChromeOS. See http://developer.chrome.com/extensions/desktop_notifications.html for details.
Second, the notification might be null if it's closed by the user; I'd try this:
function showNotify()
{
if (notification == null)
{
notification = webkitNotifications.createNotification(
'icon48.png',
'Secure page detected.',
'Checking "Enable HTTPS reading" in the setting is required.'
);
}
notification.show();
}
Upvotes: 1