Javascript chrome.tabs.captureVisibleTab在chrome.tabs.update之后作为同步回调失败?
我目前正试图弄清楚如何通过扩展在Chrome浏览器上自动截屏。我已经找到了chrome.tabs.captureVisibleTab,但遇到了一个奇怪的问题:Javascript chrome.tabs.captureVisibleTab在chrome.tabs.update之后作为同步回调失败?,javascript,google-chrome,google-chrome-extension,callback,Javascript,Google Chrome,Google Chrome Extension,Callback,我目前正试图弄清楚如何通过扩展在Chrome浏览器上自动截屏。我已经找到了chrome.tabs.captureVisibleTab,但遇到了一个奇怪的问题: chrome.tabs.update(tabId, { active: true }, function() { chrome.tabs.captureVisibleTab(null, {}, function(data) { // Going to canvas that data so hard..
chrome.tabs.update(tabId, { active: true }, function() {
chrome.tabs.captureVisibleTab(null, {}, function(data) {
// Going to canvas that data so hard...
// The system's going think it's tainted
});
});
上述操作失败,并显示以下消息:
Unchecked runtime.lastError while running tabs.captureVisibleTab: Failed to capture tab: unknown error
at Object.capture [as callback]
但是,如果我将其更改为以下内容:
chrome.tabs.update(tabId, { active: true }, function() {
setTimeout(function() {
chrome.tabs.captureVisibleTab(null, {}, function(data) {
// Going to canvas that data so hard...
// The system's going think it's tainted
});
}, 0);
});
代码顺利通过。但是,回调最终是异步的。目前,我的扩展可以“并行”地自动化多个选项卡。我担心在执行第一个chrome.tabs.captureVisibleTab
之前,可能会调用多个chrome.tabs.update
想法?我忽略了什么?还是一个潜在的bug?非常感谢您的任何见解。请尝试manifest.json中的
“权限”:[“选项卡”,“]
。这为我解决了问题。您能提供更多详细信息吗?比如什么时候调用chrome.tabs.update
和manifest.json
?