使用 chrome.tabs.captureVisibleTab 的屏幕截图

Screenshot using chrome.tabs.captureVisibleTab

我正在尝试使用 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 });
        });
    }
});

但是当我尝试捕获选项卡时出现此错误:

未选中 runtime.lastError 而 运行 tabs.captureVisibleTab: '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> 作为匹配的东西,但我缺少的是 <all_urls> 许可 。我加了权限后就成功了