2013-08-29 39 views
0

我试图创建一个弹出窗口,将可见标签显示为小图像。从chrome.tabs.captureVisibleTab()函数返回的ImgSrc是“未定义”。我试过从各个地方运行。我可以验证从tabs.Query()返回的tab是否为null,因此tabs [0] .id不为空。Chrome Tabs.CaptureVisibleTab未定义

我这样做不正确吗?

这里是我的清单,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>" 
    ] 
} 

popup.html:

<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:

$(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>"); 
     } 
    ); 
    } 
); 
}); 

回答

2

captureVisibleTab只适用于窗口中的当前活动选项卡。因此我需要传入窗口标识,而不是标签标识。需要

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>"); 
     } 
    ); 
    } 
); 
});