最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - screenshot of all tabs chrome extension - Stack Overflow

programmeradmin2浏览0评论

I'm new, I need to know how to get screenshots of all the tabs at the same time, I've used the function chrome.tabs.captureVisibleTab but as a parameter window, how can I do?Thanks!

I'm new, I need to know how to get screenshots of all the tabs at the same time, I've used the function chrome.tabs.captureVisibleTab but as a parameter window, how can I do?Thanks!

Share Improve this question asked May 15, 2012 at 14:12 Gabriele FormisanoGabriele Formisano 711 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You'll have to bring up each tab in the window with tabs.update and capture it.

function captureWindowTabs(windowId, callbackWithDataUrlArray) {
    var dataUrlArray = [];

    // get all tabs in the window
    chrome.windows.get(windowId, {populate:true}, function(windowObj) {
        var tabArray = windowObj.tabs;

        // find the tab selected at first
        for(var i = 0; i < tabArray.length; ++i) {
            if(tabArray[i].active) {
                var currentTab = tabArray[i];
                break;
            }
        }

        // recursive function that captures the tab and switches to the next
        var photoTab = function(i) {
            chrome.tabs.update(tabArray[i].id, {active:true}, function() {
                chrome.tabs.captureVisibleTab(windowId, {format:"png"}, function(dataUrl) {
                    // add data URL to array
                    dataUrlArray.push({tabId:tabArray[i].id, dataUrl:dataUrl});

                    // switch to the next tab if there is one
                    if(tabArray[i+1] != undefined) {
                        photoTab(i+1);
                    }
                    else {
                        // if no more tabs, return to the original tab and fire callback
                        chrome.tabs.update(currentTab.id, {active:true}, function() {
                            callbackWithDataUrlArray(dataUrlArray);
                        });
                    }
                });
            });
        }
        photoTab(0);
    });
}

// get all tabs in the current window
captureWindowTabs(chrome.windows.WINDOW_ID_CURRENT, function(dataArray) {
    for(var i = 0; i < dataArray.length; ++i) {
        alert(dataArray[i].dataUrl); // log to the background page or popup
    }
});
发布评论

评论列表(0)

  1. 暂无评论