Focus and blur events are not available in the background area of any extension, even those that do not use Crossrider.
A common solution is to use the extension area (extension.js) to detect events and then transfer information to the background page using messaging .
, :
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]