How can i check whether the browser is active or not in crossrider? -
i need calculate browser using time in extension. if can check whether browser active or not, easy calculate time. how possible in crossrider?
var focused = true; window.onfocus = window.onblur = function(e) { focused = (e || event).type === "focus"; } alert(focused);
i tried code in background.js display "true" if minimize browser window.
the focus , blur events not available in background scope of extension, ones not using crossrider.
the common solution use extension scope (extension.js) detect events , pass information background page using messaging.
using code base, following example should achieve goal:
extension.js
appapi.ready(function($) { window.onfocus = window.onblur = function(e) { appapi.message.tobackground({ focus: (e || event).type === "focus" }); } });
background.js
appapi.ready(function($) { appapi.message.addlistener(function(msg) { console.log('focus: '+msg.focus); }); });
[diclosure: crossrider employee]
Comments
Post a Comment