我正在尝试使用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>
为什么会出现这个错误?