title: Chrome Extension API: chrome.tabs.captureVisibleTab on Background Page to Content Script
body: <p>My overall goal was to take a screenshot via the background page using:</p>
  
  <p><a href="http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab" rel="nofollow">http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab</a></p>
  
  <p>and pass it to the content script so I can use the page's HTML DOM to analyze the screenshot and cut it up the way I would like.</p>
  
  <p>However, I can't seem to pass the dataUrl back to the content script with Message Passing:</p>
  
  <p><a href="http://developer.chrome.com/extensions/messaging.html" rel="nofollow">http://developer.chrome.com/extensions/messaging.html</a></p>
  
  <p>I tried JSON.stringify() but to no avail.</p>
  
  <p>This works perfectly fine:</p>
  
  <pre><code>background.js
  
  chrome.runtime.onMessage.addListener(
      function(request, sender, sendResponse) {
          sendResponse({imgSrc:'hello'});
      }
  );
  </code></pre>
  
  <p>I switch the code to this and nothing gets through:</p>
  
  <pre><code>background.js
  
  chrome.runtime.onMessage.addListener(
      function(request, sender, sendResponse) {
          chrome.tabs.captureVisibleTab(
              null,
              {},
              function(dataUrl)
              {
                  sendResponse({imgSrc:dataUrl});
              }
          )
      }
  );
  </code></pre>
  
  <p>My only proof that the background page is actually taking a screenshot is that I can do</p>
  
  <pre><code>chrome.tabs.captureVisibleTab(null,{},function(dataUrl){console.log(dataUrl);});
  </code></pre>
  
  <p>and I see </p>
  
  <p>"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAA....etc..."</p>
  
  <p>logged in background.html, which is valid</p>
  
  <p><strong>My question is: How can I send this URL to the content script?</strong></p>
  
  <p>I would prefer not to do all the logic on the background page which can't control anything on the actual visible page.</p>