最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论