title: Chrome Extension how to send data from content script to popup.html
body: <p>I know this this has been asked in numerous posts but honestly I don't get them. I am new to JavaScript, Chrome Extensions and everything and I have this class assignment.
  So I need to make a plugin that would count DOM objects on any given page using Cross Domain Requests. 
  I've been able to achieve this so far using Chrome Extension API's. 
  Now the problem is I need to show the data on my popup.html page from the contentScript.js file. 
  I don't know how to do that I've tried reading the documentation but messaging in chrome I just can't understand what to do. </p>
  
  <p>following is the code so far. </p>
  
  <p>manifest.json</p>
  
  <pre><code>{
  "manifest_version":2,
  
  "name":"Dom Reader",
  "description":"Counts Dom Objects",
  "version":"1.0",
  
  "page_action": {
      "default_icon":"icon.png",
      "default_title":"Dom Reader",
      "default_popup":"popup.html"
  },
  
  "background":{
      "scripts":["eventPage.js"],
      "persistent":false
  },
  
  "content_scripts":[
      {
          "matches":["http://pluralsight.com/training/Courses/*", "http://pluralsight.com/training/Authors/Details/*",                                          "https://www.youtube.com/user/*", "https://sites.google.com/site/*", "http://127.0.0.1:3667/popup.html"],
          "js":["domReader_cs.js","jquery-1.10.2.js"]
          //"css":["pluralsight_cs.css"]
      }
  ],
  
  "permissions":[
      "tabs",
      "http://pluralsight.com/*",
      "http://youtube.com/*",
      "https://sites.google.com/*",
      "http://127.0.0.1:3667/*"
  ]
  </code></pre>
  
  <p>popup.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  
      &lt;title&gt; Dom Reader &lt;/title&gt;    
      &lt;script src="jquery-1.10.2.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="popup.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;body&gt;
      &lt;H1&gt; Dom Reader &lt;/H1&gt;
      &lt;input type="submit" id="readDom" value="Read DOM Objects" /&gt;
  
     &lt;div id="domInfo"&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>eventPage.js</p>
  
  <pre><code>var value1,value2,value3;
  
  chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  if (request.action == "show") {
      chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
          chrome.pageAction.show(tabs[0].id);
      });
  }
  
  value1 = request.tElements;
  });
  </code></pre>
  
  <p>popup.js</p>
  
  <pre><code>$(function (){
  $('#readDom').click(function(){
  chrome.tabs.query({active: true, currentWindow: true}, function (tabs){
      chrome.tabs.sendMessage(tabs[0].id, {action: "readDom"});
  
   });
  });
  });
  </code></pre>
  
  <p>contentScript</p>
  
  <pre><code>var totalElements;
  var inputFields;
  var buttonElement;
  
  chrome.runtime.onMessage.addListener(function (request, sender, sendResponse){
  if(request.action == "readDom"){
  
      totalElements = $("*").length;
      inputFields = $("input").length;
      buttonElement = $("button").length;
  
  
  }
  })
  
  chrome.runtime.sendMessage({ 
  action: "show", 
  tElements: totalElements, 
  Ifields: inputFields, 
  bElements: buttonElement 
  
  });
  </code></pre>
  
  <p>Any help would be appreciated and please avoid any noobness I did :) </p>