My chrome.tabs.query code does not seem to execute when looking my extension in the debugger. I'm experimenting with the chrome.storage API to log the number of times articles at nytimes.com are accessed, and since I've added the chrome.storage code at the beginning the debugger seems not to enter the chrome.tabs.query function.
var nytCount = chrome.storage.local.get["nyt"];
// if nytCount doesn't exist in chrome local storage, set to 0
if (nytCount === undefined)
{
nytCount = 0;
}
/*
* Below is adapted from user Rob W at Stack Overflow (http://stackoverflow.com/questions/10413911/how-to-get-the-currently-opened-tabs-url-in-my-page-action-popup/10417327#10417327)
*
// Gets URL from currently active window (this should all be onload I suspect)*/
chrome.tabs.query({
// Select active tabs
active: true,
// In the current window
windowId: chrome.windows.WINDOW_ID_CURRENT
}, function(array_of_Tabs) {
// Since there can only be one active tab in one active window, the array has only one element
var tab = array_of_Tabs[0];
var title = tab.title;
if (title.indexOf("NYTimes.com") !== -1)
{
nytCount++;
}
// rest of if conditions for those sites that have identifiers in tab titles
});
alert(nytCount);
Any ideas? It worked fine before when I initialized nytCount to 0, but then of course its value could only go up to 1 before it would be reinitialized on the next runthrough of the code.