8
chrome.tabs.query({ 
    active: true, 
    currentWindow: true 
    }, 
    function (tabs) { 
    chrome.tabs.captureVisibleTab(null 
     ,{ format: "png"}, 
     function (src) { 
      $('body').append("<img src='" + src + "'>" + tabs[0].url + "</img>");//appends captured image to the popup.html 
     } 
    ); 
}); 

이 코드는 캡처 한 이미지를 popup.html의 본문에 추가합니다. 하지만 내가 원하는 것은 popup body에 이미지를 추가하는 것이다. chrome.tabs.create ({url : "newtab.html")를 사용하여 새 탭을 열고 캡처 한 이미지를이 newtab.html에 추가하려고한다. 'newtab.html'은 이미 경로 폴더에 있음). 사전크롬 확장 - 새 탭에서 캡처 된 스크린 샷 열기

답변

2

에서

덕분에 내가 previosuly here 설명 방법이있다.

요점은 스크립트가 포함 된 탭을 열고 메시징을 사용하여 통신하는 것입니다.

작은 문제는 새로 열린 페이지가 언제 준비되었는지 알 수 없다는 것입니다. 나는 새로 열린 페이지를 배경 페이지에 연결 시켜서 해결했지만, 하나의 전역 변수 만 가지고 있으면서도 엉망이었다.

더 나은 솔루션이 그런 원샷 이벤트 리스너, 뭔가 될 것이다 :보다

// Execute this code from the background page, not the popup! 
function openScreenshot(src){ 
    chrome.tabs.create(
    { url: chrome.runtime.getURL("newtab.html") }, 
    function(tab) { 
     chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { 
     // If the request is expected and comes from the tab we just opened 
     if(message.getScreenshot && sender.tab.id == tab.id) { 
      sendResponse(src); 
      // Ensure we're only run once 
      chrome.runtime.onMessage.removeListener(arguments.callee); 
     } 
     }); 
    } 
); 
} 

기타, 링크 된 답을 따릅니다.