title: Chrome extension: Communication between content script and background.html
body: <p>I am new to Chrome extensions. I am trying to communicate between the content script and the <em>background.html</em> page. The <em>background.html</em> sends a request, "<em>hello</em>", to the content script and the content script should respond back with "<em>hello background</em>" alert. But it's just not happening. My <em>background.html</em> code is:</p>
  
  <pre><code>function testRequest() {        
      chrome.tabs.getSelected(null, function(tab) {
          chrome.tabs.sendRequest(tab.id, {greeting: "hello"});
      });    
  }
  </code></pre>
  
  <p><em>content.js</em> code:</p>
  
  <pre><code>chrome.extension.onMessage.addListener(
      function(request, sender, sendResponse) {
          if (request.greeting == "hello")
          alert("hello background");
      }
  );
  </code></pre>
  
  <p><em>popup.html</em> code:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;form&gt;
              &lt;input type="button" value="sendMessage" onclick="testRequest()" /&gt;
          &lt;/form&gt;    
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em>manifest.json</em>:</p>
  
  <pre><code>{
      "browser_action": {
          "default_icon": "icon.png",
          "popup": "popup.html"
      },
      "background": {
          "page": "background.html"
      },
      "permissions": [
          "tabs",
          "http://*/*",
          "https://*/*",
          "notifications",
          "contextMenus"
      ],
      "content_scripts": [
          {
              "matches": ["http://*/*","https://*/*"],
              "js": ["content.js"]
          }
      ],
      "name": "FirstExtension",
      "version": "1.0"
  }
  </code></pre>
  
  <p>Please help!</p>