2013-08-29 4 views
0

보이는 탭을 작은 이미지로 표시하는 팝업을 만들려고합니다. chrome.tabs.captureVisibleTab() 함수에서 반환 된 ImgSrc은 "정의되지 않음"입니다. 나는 이것을 여러 곳에서 달리기를 시도했다. tabs.Query()에서 반환 된 탭이 null이 아니므로 tab [0] .id가 null이 아님을 확인할 수 있습니다.Chrome Tabs.CaptureVisibleTab이 정의되지 않았습니다.

내가 잘못 했습니까?

{ 
    "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.html 및 popup.js 파일입니다 윈도우 내의 현재의 액티브 한 탭 따라서 tab-id가 아닌 window-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>"); 
     } 
    ); 
    } 
); 
}); 
관련 문제