No one seems to respond...This bug needs to be fixed...But for now i have made my own custom focuschange event using chromeapi's and blur and focus events of page and other can use it also....
The idea is we inject a js in every frame at document start which will send focus and blur events, so that we don't get focus event at first as we already are in focus....Because i inject my other working js in document end....Then we process it in background js and use chrome api's to decide focus or not focus....
Below is the code for this.
put following on background js file
===============================
function ChromeWindow(list)
{
this.focusedwindow = null;
this.Event = Event;
this.FocusEvtListner = list;
function Event(tab,request)
{
if(request == undefined || tab == undefined)
return;
if(request.command == "winevent")
{
console.log(request.state+" domain="+request.domain);
chrome.windows.get(tab.windowId ,winget.bind(this));
function winget(win)
{
if(win == undefined || win == null)
return;
if(this.focusedwindow == null)
{
this.focusedwindow = win;
if(tab.status == "complete")
this.FocusEvtListner(win,tab);
}
else if(
this.focusedwindow.id!=
win.id || this.focusedwindow.focused!=win.focused)
{
console.log("diff chrome win or state changed");
this.focusedwindow = win;
if(tab.status == "complete")
this.FocusEvtListner(win,tab);
}
else
console.log("same chrome win");
console.log("chrome winid="+
win.id +" state ="+win.state +" focused="+win.focused );
}
}
}
}
_ChromeWindow = new ChromeWindow(OnFocusEvt);
function OnFocusEvt(win,tab)
{
console.log("\n\nOnFocusEvt start");
if(win.focused)
console.log("focused");
else
console.log("not focused");
console.log("OnFocusEvt winid="+
win.id +" state ="+win.state +" focused="+win.focused +" tab.status="+tab.status);
console.log("OnFocusEvt taburl ="+tab.url);
}
chrome.runtime.onMessage.addListener(OnRequest);
function OnRequest(request, sender, sendResponse)
{
consolelog(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
_ChromeWindow.Event(sender.tab,request);
return;
}
=============================================================
another content script ...injected at document start
focusevt.js
{
"matches": ["<all_urls>"],
"js": ["focusevt.js"],
"run_at" : "document_start",
"all_frames": true
}
window.onblur = function()
{
chrome.runtime.sendMessage({command:"winevent",state:"blur",domain:document.domain});
}
window.onfocus = function()
{
chrome.runtime.sendMessage({command:"winevent",state:"focus",domain:document.domain});