in my Firefox extension I try to handle the event when the browser window is activated or deactivated. Adding the events \"activate\" and \"deactivate\" to the window does basic
If I understand you correctly, you can use this:
window.addEventListener("blur",function(){ //mystuff },false);
and this:
window.addEventListener("focus",function(){ //mystuff },false);