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

यह कोड पॉपअप.html के शरीर में कैप्चर की गई छवि को जोड़ता है। लेकिन मैं चाहता हूं कि पॉपअप बॉडी में छवि को जोड़ने का प्रयास किया जाए, मैं 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); 
     } 
     }); 
    } 
); 
} 

उसके अलावा, जुड़ा हुआ जवाब का पालन करें।

संबंधित मुद्दे