Google chrome Chrome Tabs.CaptureVisibleTab未定义

Google chrome Chrome Tabs.CaptureVisibleTab未定义,google-chrome,google-chrome-extension,Google Chrome,Google Chrome Extension,我正在尝试创建一个弹出窗口,将可见选项卡显示为一个小图像。从chrome.tabs.captureVisibleTab()函数返回的ImgSrc为“未定义”。我试过在不同的地方运行这个。我可以验证从tabs.Query()返回的选项卡是否不为null,因此选项卡[0].id是否为null 我做得不对吗 这是我的清单、popup.html和popup.js文件: { "manifest_version": 2, "name": "SuperFave", "description":

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

我做得不对吗

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

{
  "manifest_version": 2,

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

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

  "permissions": [
    "tabs",
    "<all_urls>"
  ]
}
{
“清单版本”:2,
“名称”:“超级大道”,
“说明”:“保存收藏夹演示”,
“版本”:“1.0”,
“浏览器操作”:{
“默认弹出窗口”:“popup.html”
},
“权限”:[
“标签”,
"");
}
); 
}
);
});

captureVisibleTab仅对窗口中当前活动的选项卡有效。因此,我需要传入窗口id,而不是选项卡id

popup.js需要:

$(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>");
        }
      ); 
    }
  );
});
$(文档).ready(函数(){
chrome.tabs.query({
//获取用户当前可以看到的窗口
主动:对,
currentWindow:真
},
功能(选项卡){
chrome.tabs.captureVisibleTab(
chrome.windows.WINDOW\u ID\u当前,
功能(src){
//显示指向图像的链接。可替换为
//验证结果是否为“未定义”
$('body')。追加(“”);
}
); 
}
);
});
$(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>");
        }
      ); 
    }
  );
});
$(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>");
        }
      ); 
    }
  );
});