title: Listener in a Content Script
body: <p>Let me explain my issue. I'm currently developing an Google Chrome Extension which inject a toolbar as an iframe in every web page.</p>
  
  <p>The problem is that i need in some case to hide the toolbar, re-display it and things like that. Basicelly i was thinking to put my listener on my background-page, but it's useless because this page can't manipulate graphicely the object. So my plan was to put this listener on a content_script (who can manipulate graphiquely the objet). But the second problem is that a content-script in opposite to a background-page is not executed all the time but only once.</p>
  
  <p>So i'm asking myself if it's possible to make a content-script sounds like a background-page, by putting a loop on it or something like that...</p>
  
  <p>Thanks in advance.</p>
  
  <p>I've tried this :</p>
  
  <p>manifest.json</p>
  
  <pre><code>{   
      "background_page" : "background.html",
      "browser_action" :
      {
          "default_icon" : "images/extension.png"
          //"popup" : "activateToolbar.html"
      },
      "content_scripts": 
      [ {
            "all_frames": true,
            "css": ["css/yourtoolbar.css"],
            "js": ["js/jquery.js", "js/yourtoolbar.js", "js/listener.js"],
            "matches": ["http://*/*"],
            "run_at": "document_end"
      } ], 
      "permissions" : ["tabs", "unlimitedStorage", "http://*/*", "notifications"],    
      "name" : "YourToolbar",
      "version" : "1.1",
      "description" : "Make your own Toolbar"
  }
  </code></pre>
  
  <p>toolbar.html</p>
  
  <pre><code>&lt;!-- Close Button --&gt;
              &lt;a href="javascript:hideToolbar()"&gt;&lt;input type="image" src="images/close.png" name="close" width="18" height="18"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Tool.js</p>
  
  <pre><code>function hideToolbar()
  {
      chrome.extension.sendRequest({action : "hideToolbar"});
      window.webkitNotifications.createHTMLNotification('instantMessage.html', 'Ask Show Menu').show();
  }
  </code></pre>
  
  <p>listener.js</p>
  
  <pre><code>chrome.extension.onRequest.addListener(function(request, sender, sendResponse){
      if(request.action)
      {
          $('body').remove();
          console.log('Received Start');
          alert(request.action);
          console.log('Received End');
      }
      else
      {
          console.log('nothing');
          alert('Not For Me [listener.js]');
      }
  });
  </code></pre>
  
  <p>background.js</p>
  
  <pre><code>chrome.extension.onRequest.addListener(function(request, sender, sendResponse) 
  {   
      if(request.newTab) 
      {
          // Create a new Tab
          chrome.tabs.create({url: request.newTab});
      }
      else if(request.newWindow)
      {
          // Create a new Window
          chrome.windows.create({url: request.newWindow});
      }
      else if(request.action)
      {       
          chrome.tabs.getAllInWindow(null, function(tabs) {
            $.each(tabs, function() {
              chrome.tabs.sendRequest(this.id, {"action":"hideToolbar"} );
            });
          });
      }
  });
  </code></pre>
  
  <p>But the problem is that the addListener didn't block the execution and he just didn't catch anything...</p>