title: how to send message from background to content script?
body: <p>i am sending message from background to content script.
  My background.js</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
   function(request, sender, sendResponse) {
    switch(request.type){
      case "login-check":
       checkLogin();
      break;
    }
  });
  
  function checkLogin() {
   // var test = localStorage.getItem("test");
   // alert(test);
   chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ 
    chrome.tabs.sendMessage(tabs[0].id, {type: "login"}, function(response) {
     console.log(response.farewell);
     //alert(response.farewell);
    }); 
   });
  }
  </code></pre>
  
  <p>My content-script.js</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
      if (request.type == "login")
        sendResponse({farewell: "goodbye"});
    });
  </code></pre>
  
  <p>it is showing me an error "Error in event handler for (unknown): TypeError: Cannot read property 'farewell' of undefined
  ".
  i have tried all the ways almost but it didn't work please help.
  thanks in advance</p>