1

I'm writing an extention that saves all the tabs when you close Chrome. My background.js looks like:

chrome.windows.onRemoved.addListener(saveTabs);
function saveTabs(win) {
    // recentlyWinClosedTabs is a dictionary included all closed tabs
    var jsonData = JSON.stringify(recentlyWinClosedTabs);
    chrome.storage.local.set({ 'RecentClosedTabs': jsonData });
}

and my popup.js looks like:

function loadRCWinTabsInfo() {
    chrome.storage.local.get('RecentClosedTabs', function (items) {
        allOpenedTabsInDiffWin = JSON.parse(items.RecentClosedTabs);
        if (allOpenedTabsInDiffWin != null && typeof allOpenedTabsInDiffWin != "undefined") {
            //show tabs info
        }
    });
}

Every time I close a window, it should save all the tabs of that window. However, you have to have the "Continue running background apps when Google Chrome is closed" setting is set. So, is it possible to execute some code when the window is closed?

4

0 回答 0