diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-14 17:39:52 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-14 17:39:52 -0400 |
| commit | cf2f19f91ec703244204de039c6663f76c722c77 (patch) | |
| tree | 944c1b42a72fb6dab8c7db12424902afd8808e68 /chrome-extension | |
| parent | dd5bee919c00a372679858f9ba10e4caf6170fb1 (diff) | |
| download | browsing-activity-tracker-cf2f19f91ec703244204de039c6663f76c722c77.tar.gz | |
Make event logging more conservative in case of multiple windows
Diffstat (limited to 'chrome-extension')
| -rw-r--r-- | chrome-extension/bg.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/chrome-extension/bg.js b/chrome-extension/bg.js index 4b39611..208b7bd 100644 --- a/chrome-extension/bg.js +++ b/chrome-extension/bg.js @@ -20,15 +20,23 @@ function log(url, title){ chrome.tabs.onActivated.addListener(function (activeInfo) { chrome.tabs.get(activeInfo.tabId, function(tab) { - if (tab.status === "complete") { - log(tab.url, tab.title); + if (tab.status === "complete" && tab.active) { + chrome.windows.get(tab.windowId, {populate: false}, function(window) { + if (window.focused) { + log(tab.url, tab.title); + } + }); } }); }); chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { if (changeInfo.status === "complete" && tab.active) { - log(tab.url, tab.title); + chrome.windows.get(tab.windowId, {populate: false}, function(window) { + if (window.focused) { + log(tab.url, tab.title); + } + }); } }); @@ -36,12 +44,14 @@ chrome.windows.onFocusChanged.addListener(function (windowId) { if (windowId == chrome.windows.WINDOW_ID_NONE) { log(null, null); } else { - chrome.tabs.query({active: true, currentWindow: true}, function (tabs) { - if (tabs[0].status === "complete") { - log(tabs[0].url, tabs[0].title); + chrome.windows.get(windowId, {populate: true}, function(window) { + if (window.focused) { + chrome.tabs.query({active: true, windowId: windowId}, function (tabs) { + if (tabs[0].status === "complete") { + log(tabs[0].url, tabs[0].title); + } + }); } }); } }); - - |
