title: Google Chrome Extension : Port: Could not establish connection. Receiving end does not exist
body: <p>I have been looking for an answer for almost a week now, but having read all the stackoverflow items i can't seem to find a solution that is working for me. </p>
  
  <p>The error that i'm having is :</p>
  
  <pre><code>Port: Could not establish connection. Receiving end does not exist. lastError:30 set   lastError:30 dispatchOnDisconnect messaging:277
  </code></pre>
  
  <p>folder layout : </p>
  
  <pre><code>img
     developer_icon.png
  js
     sidebar.js
     main.js
     jquery-2.0.3.js
  manifest.json
  </code></pre>
  
  <p>my the manifest.json file looks something like this (it is version 2) :`</p>
  
  <pre><code>"browser_action": {
    "default_icon": "./img/developer_icon.png"
  },
  
  "content_scripts": [
  {      
    "matches": ["*://*/*"],
    "js": ["./js/sidebar.js"],   
    "run_at": "document_end"
  }
  ],
  
  "background" : {
      "scripts" : ["./js/main.js","./js/jquery-2.0.3.js"] 
  },
  </code></pre>
  
  <p>I want to handle the user clicking the extension icon so i could inject a sidebar in the existing website (because the extension i would like to develop requires that amount of space). So in main.js : </p>
  
  <pre><code>chrome.browserAction.onClicked.addListener(function(tab) {          
          chrome.tabs.getSelected(null, function(tab){        
              chrome.tabs.sendMessage(
                  //Selected tab id
                  tab.id,                         
                  //Params inside a object data
                  {callFunction: "toggleSidebar"}, 
                  //Optional callback function
                  function(response) {
                      console.log(response);
                  }
              );
          });
      });
  </code></pre>
  
  <p>and in sidebar.js : </p>
  
  <pre><code>chrome.runtime.onMessage.addListener(function(req,sender,sendResponse){
      console.log("sidebar handling request");
      toggleSidebar();
  });
  </code></pre>
  
  <p>but i'm never able to see the console.log in my console because of the error. Does someone know what i did wrong? </p>
  
  <p>Thanks in advance!</p>