diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-14 22:46:52 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2014-07-14 22:46:52 -0400 |
| commit | 170f9faa87ec72cc422f1da129ff5f5576caff73 (patch) | |
| tree | 7fed60cad9027b4a761af9b6a161ea19949d7df1 | |
| parent | 77956372fe739aba405f6fd48fd633bed6a1eb87 (diff) | |
| download | browsing-activity-tracker-170f9faa87ec72cc422f1da129ff5f5576caff73.tar.gz | |
[Firefox add-on] Window activation events more robusts when several windows
Since there is only one active tab across all the windows, switching between
two windows will generate both a window activation, and tab activation event
for the window being switched to. By keeping track of the previously focused
window, we disable the activation event for the window being switched to.
| -rw-r--r-- | firefox-addon/lib/main.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/firefox-addon/lib/main.js b/firefox-addon/lib/main.js index 5814792..285397b 100644 --- a/firefox-addon/lib/main.js +++ b/firefox-addon/lib/main.js @@ -4,6 +4,8 @@ var Request = require("sdk/request").Request; var prefs = require("sdk/simple-prefs").prefs; var XMLHttpRequest = require("sdk/net/xhr").XMLHttpRequest; +var previous_window = null; + function log(url, title){ var data = JSON.stringify({ url: url, time: Date.now(), @@ -21,6 +23,14 @@ function logTab(tab) { } tabs.on("activate", function () { logTab(tabs.activeTab) }); + tabs.on("pageshow", logTab ); -windows.on("activate", function () { logTab(tabs.activeTab) }); -windows.on("deactivate", function () { log(null, null) }); +windows.on("activate", function (window) { + if (previous_window != window) { + previous_window = window; + return; + } + logTab(tabs.activeTab) ; +}); + +windows.on("deactivate", function (window) { log(null, null) }); |
