chris
chris

Reputation: 1894

Screenshot using chrome.tabs.captureVisibleTab

I'm trying to capture the visible area of a page using chrome.tabs.captureVisibleTab. Here is the code that makes the call:

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.name == 'screenshot') {
        chrome.tabs.captureVisibleTab(null, null, function(dataUrl) {
            sendResponse({ screenshotUrl: dataUrl });
        });
    }
});

But when I try to capture the tab I get this error:

Unchecked runtime.lastError while running tabs.captureVisibleTab: The 'activeTab' permission is not in effect because this extension has not been in invoked.

Here is my manifest file:

   {
  "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"
      ]
    }
  ]
}

Why do I get that error?

Upvotes: 5

Views: 4760

Answers (1)

chris
chris

Reputation: 1894

There are things that talk about <all_urls> as something to match, but what I was missing was the <all_urls> permission. After I added the permission, it worked.

Upvotes: 7

Related Questions