javascript - Screenshot using chrome.tabs.captureVisibleTab - Stack Overflow

I'm trying to capture the visible area of a page using chrome.tabs.captureVisibleTab. Here is the

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"
      ]
    }
  ]
}
  • I have active tab permissions
  • The call is being made from a background script
  • I'm matching <all_urls>

Why do I get that error?

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"
      ]
    }
  ]
}
  • I have active tab permissions
  • The call is being made from a background script
  • I'm matching <all_urls>

Why do I get that error?

Share Improve this question edited Feb 3, 2015 at 22:04 chris asked Feb 3, 2015 at 21:08 chrischris 1,8931 gold badge19 silver badges33 bronze badges 4
  • 1 Probably duplicate with this one: stackoverflow./questions/25964869/… – Dayton Wang Commented Feb 3, 2015 at 21:21
  • I'm using the all_urls permission, so that answer doesn't really fit my question. – chris Commented Feb 3, 2015 at 22:03
  • 1 But there's no "<all_urls>" in your "permissions" of manifest. – Dayton Wang Commented Feb 3, 2015 at 22:42
  • Ha, thank you! :) I didn't realize that <all_urls> could be something to match against as well as a permission. That did it. Thank you! – chris Commented Feb 3, 2015 at 22:54
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742269140a4412367.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信