title: Pass a variable from content script to popup
body: <p>I'm messing around (trying to learn) how to make a chrome extension. Right now I'm just making super simple one where it counts instances of a certain word on a page. I have this part working.</p>
  
  <p>What I want to do is send this information to the pop so I can use it to do some other stuff.</p>
  
  <p>Here is what I have so far:</p>
  
  <p>manifest.json</p>
  
  <pre><code>{
      "manifest_version": 2,
      "name": "WeedKiller",
      "description": "Totally serious $100% legit extension",
      "version": "0.1",
  
      "background": {
          "persistent": false,
          "scripts": ["background.js"]
      },
  
      "permissions":[
          "tabs",
          "storage"
      ],
      "browser_action": {
      "default_icon": "icon.png",
      "default_title": "WeedKiller",
      "default_popup": "popup.html"
      },
      "content_scripts": [
          {
              "matches": [
                  "http://*/*",
                  "https://*/*"
              ],
              "js": [
                  "content.js"
              ],
              "run_at": "document_end"
          }
      ]
  }
  </code></pre>
  
  <p>content.js</p>
  
  <pre><code>var elements = document.getElementsByTagName('*');
  var count = 0;
  
  function tokeCounter(){
      for (var i = 0; i &lt; elements.length; i++) {
          var element = elements[i];
  
          for (var j = 0; j &lt; element.childNodes.length; j++) {
              var node = element.childNodes[j];
  
              if (node.nodeType === 3) {
                  var text = node.nodeValue;
                  if(text == '420'){
                      count++; 
                  }
  
                  var replacedText = text.replace(/420/, '+1');
  
                  if (replacedText !== text) {
                      element.replaceChild(document.createTextNode(replacedText), node);
                  }
              }
          }    
      }
  }
  
  tokeCounter();
  </code></pre>
  
  <p>So what I want to happen is to send the <code>count</code> variable to the popup so that I can use it there. </p>
  
  <p>I have looked around and found that I need to do something with <code>chrome.runtime.sendMessage</code>.</p>
  
  <p>I have it so I add this line to the end of content.js:</p>
  
  <pre><code> chrome.runtime.sendMessage(count);
  </code></pre>
  
  <p>and then in background.js:</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
      function(response, sender, sendResponse){      
         temp = response;
      }
  );
  </code></pre>
  
  <p>I'm sort of stuck here as I'm not sure how to send this information to popup and use it.</p>