title: Message passing from extension to background page
body: <p>I'm trying to create a page action extension in chrome. I have an html page corresponding to the popup that gets displayed on clicking the page action. I have included a script file <code>popup.js</code> in this html page. From this page I'm trying to send a message to a background js file <code>background.js</code>. The problem is that I'm calling <code>sendRequest</code> only once from <code>popup.js</code> but I'm receiving it in the background page multiple times. I'm doing a file action there which results in script errors because of concurrent access. I'm pasting the code related to message passing here</p>
  
  <p><strong>extension file - popup.js</strong></p>
  
  <pre><code>chrome.extension.sendRequest({"intent" : "read"}, function (message) {
        console.log(message);
  });
  </code></pre>
  
  <p><strong>background page - background.js</strong></p>
  
  <pre><code>(function(){
  var fileName = "credentials.txt";
  var fileSystem;
  
  function checkUrl(tabId, changeInfo, tab) {
      if(/https?:\/\/.*?\/olc/.test(tab.url)) {
          chrome.pageAction.show(tabId);
          chrome.extension.onRequest.addListener(function (request, sender, callback) {
              callback("printed");
          });
      }
  }
  chrome.tabs.onUpdated.addListener(checkUrl);
  })();
  </code></pre>
  
  <p>The listener is called 4 times in this case. The callback will be called the first time. The next 3 times it gives an error saying <code>Could not send response: Cannot send a response more than once per chrome.extension.onRequest listener per document (message was sent by extension kaejjpmlibijbgbgcfodphlkcjjkmjlk).</code> Can anyone help me with this?</p>