gpt4 book ai didi

javascript - 所有选项卡 chrome 扩展的屏幕截图

转载 作者:行者123 更新时间:2023-11-29 10:50:48 25 4
gpt4 key购买 nike

我是新手,我需要知道如何同时获取所有标签的屏幕截图,我使用了功能 chrome.tabs.captureVisibleTab 但是作为参数窗口,我该怎么办?谢谢!

最佳答案

您必须使用 tabs.update 在窗口中调出每个选项卡并捕获它。

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
}
});

关于javascript - 所有选项卡 chrome 扩展的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10602633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com