Reputation: 4197
I'm trying to detect if Firefox is being run in the foreground (to track time being spent on websites).
Is there an easier way than tracking new windows being activated/deactivated?
Upvotes: 1
Views: 35
Reputation: 4197
I ended up using windows.browserWindows.on close and deactivate / open and activate, coupled with tabs.on activate, deactive, close, ready and also tabs.activeTab.id/url/title
var active = true
/////////////////////////////////////////////
// Active Firefox?
////////////////////////////////////////////
// testing purpose
//tmr.setInterval(function(){console.log(active)}, 500)
//
// detect if firefox is running in foreground
//
windows.browserWindows.on('open', function(window) {
active = true
})
windows.browserWindows.on('activate', function(window) {
active = true
})
//
// detect is firefox is running in background
//
windows.browserWindows.on('deactivate', function(window) {
active = false
})
windows.browserWindows.on('close', function(window) {
active = false
})
Upvotes: 1
Reputation: 33162
tabs
module offers activate
and deactivate
events.PageMod
. Will also trigger when the browser window is minimized.Both of these will not trigger if (AFAIK) when the browser window itself becomes unfocused.
Upvotes: 1