我目前正在尝试弄清楚如何通过扩展程序在 Chrome 浏览器上自动捕获屏幕。我已经到达 chrome.tabs.captureVisibleTab
但遇到了一个奇怪的问题:
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
。
想法?我忽略了什么?还是潜在的错误?非常感谢任何见解。
最佳答案
尝试 "permissions": [ "tabs", "<all_urls>" ]
在 manifest.json 中。这为我解决了问题。
关于javascript - chrome.tabs.captureVisibleTab 在 chrome.tabs.update 之后作为同步回调失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36854483/