开发者

How to get tabs before Chrome browser window closed?

I'm using Google Chrome Extensions and I was trying to capture all the tabs before a window is closed as such:

chrome.windows.onRemoved.addLi开发者_运维百科stener(function(windowId) {
    chrome.windows.get(windowId, function(window) {
        alert(window.tabs); 
    });
});

But I think the window is actually getting destroyed before I can get to window.tabs. How would I get their ids before the window is removed?

Thanks!


You are right, in Chrome when you close a Window, all the tabs will close first, then after that the window itself will close.

If you want to capture all the tabs before a window is closed, I believe as far as I know, the best approach will be hooking up a listener to to the tabs onRemoved event http://code.google.com/chrome/extensions/tabs.html#event-onRemoved

You would have to maintain an internal cache of what is being closed, and when a window is closed, you read that cache. It might get tricky, and some problems that you need to solve.

For example, How would you know all those tabs are being closed? Perhaps the answer to that question is to make a timer of 1 second, and count all the closed tabs in that state, and reset it once the timer has ended. There might be other ways.

Hope that helped, good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜