title: How can I communicate between background.js and popup.js?
body: <p>I have an extension, with a background script:</p>
  
  <pre><code>"background": {
      "scripts": ["scripts/background.js"]
    },
  </code></pre>
  
  <p>and a content script:</p>
  
  <pre><code>"content_scripts": [
      {
        "matches": ["*://*/*"],
        "js": ["scripts/content_script.js"]
      }
    ],
  </code></pre>
  
  <p>a popup window <code>(popup.html)</code>, and a popup script <code>(popup.js)</code>. popup.js is not registrated into manifest,and it deals with popup.html look, and listen for user actions made in popup.html, such as clicking a button.</p>
  
  <p>I want to make an extension, what <strong>emails the current tab's page</strong>, and for this, I need to get the page DOM with the <code>content_script</code>, pass data (DOM) to the <code>background script</code>. After this, when the user triggers an event in popup.html, popup.js catches this event, and I want popup.js to be able to get the passed data(DOM) from background.js. How could I make this? So, my question is, how could I communicate between background.js and popup.js?</p>
  
  <hr>
  
  <p><strong>I found an answer to my own question:</strong></p>
  
  <p>Thanks Elvis, I think I solved the problem; I only need to get the DOM of site in content script, but my question's solution was this:</p>
  
  <p><strong>content_script.js</strong></p>
  
  <pre><code> // SEND DOM structure to the background page
      chrome.extension.sendRequest({dom: "page DOM here"});
  </code></pre>
  
  <p><strong>background.html</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
      if(request.dom != "")
          var theDOM = request.dom;
          console.log(request.dom); // page DOM here -&gt; works
          chrome.extension.sendRequest({theDOM: theDOM}); // theDOM : "page DOM here"
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>popup.js</strong></p>
  
  <pre><code>var dom;
  chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
      if(request.theDOM != ""){
          console.log("popup request: "+request.theDOM);
          dom = request.theDOM;
      }
  });
  
  // HANDLE TAB_1 REQUESTS (EMAIL PAGE)
  // ---------------------------------
  $("#send").click(function(){
      console.log(dom); // page DOM here
  }
  </code></pre>
  
  <p>Thanks for the help ;)</p>