我尝试使用chrome.tabs.captureVisibleTab捕获页面的可见区域。以下是进行调用的代码:
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
if (request.name == 'screenshot') {
chrome.tabs.captureVisibleTab(null, null, function(dataUrl) {
sendResponse({ screenshotUrl: dataUrl });
});
}
});
但是当我尝试捕获标签时,我收到了这个错误:
运行tabs.captureVisibleTab时未经检查的runtime.lastError:' activeTab'权限未生效,因为尚未调用此扩展名。
这是我的清单文件:
{
"manifest_version": 2,
"name": "Empathy",
"version": "0.1",
"description": "Simulate accessibility issues for websites.",
"browser_action": {
"default_icon": "empathy19.png",
"default_title": "Empathy!"
},
"permissions": [
"activeTab",
"contextMenus",
"desktopCapture",
"tabCapture",
"tts" // Text-to-speech
],
"background": {
"scripts": [
"boot.js"
],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": [
"src/helpers.js",
"src/colorblindness.js",
"lib/colorvision.js",
"lib/html2canvas.js"
]
}
]
}
<all_urls>
为什么我会收到错误?
答案 0 :(得分:5)
有些内容可以将<all_urls>
视为匹配,但我遗漏的是<all_urls>
权限。我添加了许可后,它就可以了。