首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Chrome Tabs.CaptureVisibleTab未定义

Chrome Tabs.CaptureVisibleTab未定义
EN

Stack Overflow用户
提问于 2013-08-29 00:40:40
回答 1查看 3K关注 0票数 0

我正在尝试创建一个弹出窗口,它将显示可视选项卡为一个小图像。从ImgSrc ()函数返回的chrome.tabs.captureVisibleTab是“未定义的”。我试过从不同的地方运行这个。我可以验证从tabs.Query()返回的选项卡不是空的,所以tabs.id不是空的。

我做得不对吗?

这是我的清单,popup.html和popup.js文件:

代码语言:javascript
运行
复制
{
  "manifest_version": 2,

  "name": "SuperFave",
  "description": "Saves favorites demo",
  "version": "1.0",

  "browser_action": {
    "default_popup": "popup.html"
  },

  "permissions": [
    "tabs",
    "<all_urls>"
  ]
}

popup.html:

代码语言:javascript
运行
复制
<html>
  <head>
    <script type="text/javascript" src="jquery-1.10.2.min.js">
    </script>
    <script type="text/javascript" src="popup.js">
    </script>
  </head>
  <body>
  </body>
</html>

popup.js:

代码语言:javascript
运行
复制
$(document).ready( function () {
  chrome.tabs.query( {
      // gets the window the user can currently see
      active: true, 
      currentWindow: true 
    },
    function (tabs) {
      chrome.tabs.captureVisibleTab( 
        tabs[0].id,
        function (src) {
          // displays a link to the image. Can be replaced by an alert() to 
          // verify the result is 'undefined'
          $('body').append("<a href='" + src + "'>" + tabs[0].url + "</a>");
        }
      ); 
    }
  );
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-29 01:54:00

captureVisibleTab只在窗口中的当前活动选项卡上工作。因此,我需要传入窗口id,而不是选项卡id。

popup.js必须是:

代码语言:javascript
运行
复制
$(document).ready( function () {
  chrome.tabs.query( {
      // gets the window the user can currently see
      active: true, 
      currentWindow: true 
    },
    function (tabs) {
      chrome.tabs.captureVisibleTab( 
        chrome.windows.WINDOW_ID_CURRENT,
        function (src) {
          // displays a link to the image. Can be replaced by an alert() to 
          // verify the result is 'undefined'
          $('body').append("<a href='" + src + "'>" + tabs[0].url + "</a>");
        }
      ); 
    }
  );
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18500568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档