窗口关闭后,onActivated事件触发

时间:2016-07-29 12:30:47

标签: javascript google-chrome google-chrome-extension tabs

我正在制作Chrome扩展程序,用于监控用户在网页浏览期间的活动。我为选项卡创建,选项卡删除,选项卡激活放置了一些监听器并且工作正常。问题是当我关闭带有更多选项卡的窗口时,控制台会显示: enter image description here

来自windowID 1的所有标签通常都会关闭,但是在关闭窗口之后会出现一个错误,导致第67和第61行听到onActivated

    chrome.tabs.onActivated.addListener(function(activeInfo){  
        return chrome.tabs.get(activeInfo.tabId, function(tab){ // LINE 61 
            return post_to_console({
                timestamp: gimme_timestamp(),
                activity: "TAB_ACTIVATED",
                winid: activeInfo.windowId,
                tabid: activeInfo.tabId,
                url: tab.url,  // LINE 67
                user_id: _user_id,
                fromindex: "undefined",
                toindex: "undefined"
            });
        });
});

我不确定,但我认为在选项卡和窗口关闭onActivated事件后会发生火灾。 这是关闭选项卡和关闭窗口的代码:

chrome.tabs.onRemoved.addListener(function(tab, removeInfo){
        _winid = removeInfo.windowId;
        _tabid = tab;
return post_to_console({
        timestamp: gimme_timestamp(),
        activity: "CLOSE_TAB",
        winid: _winid,
        tabid: _tabid,
        url: "undefined",
        user_id: _user_id,
        fromindex: "undefined",
        toindex: "undefined"
  });  
});
chrome.windows.onRemoved.addListener(function(win){
    return post_to_console({
        timestamp: gimme_timestamp(),
        activity: "CLOSE_WINDOW",
        winid: win,
        tabid: "undefined",
        url: "undefined",
        user_id: _user_id,
        fromindex: "undefined",
        toindex: "undefined"
  }); 
});

我知道chrome.tabs.get会抛出错误,因为在那个时间窗口中,其标签不再存在,但为什么毕竟调用onActivated事件。 我感谢任何来自我们的帮助。感谢

0 个答案:

没有答案
相关问题