title: Extension error. Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
body: <p>I have an error when I change tab in the time when I send data from content script to background script and wait for a response.
  When I am on the same tab until I get response from background script everything is fine.</p>
  <p><strong>Error info:</strong>
  Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.</p>
  <p><strong>content.js:</strong></p>
  <pre><code>window.addEventListener('load', (event) =&gt; {
      GetBgScriptStatus();
  });
  
  /* WORK with background scripts */
  
  function GetBgScriptStatus() {
      var message = { request: &quot;GetBgScriptStatus&quot; };
      SendMessageToBackgroundScript(message);
      console.log(&quot;send to bg script: &quot; + message.request);
  }
  
  function SendMessageToBackgroundScript(message) {   
      chrome.runtime.sendMessage(message, function (response) {});
  }
  
  chrome.runtime.onMessage.addListener(
      function (request, sender, sendResponse) {
          var message = request;
  
          if (message.context != null || message.request != null) {
  
  
              if(message.context == &quot;AnswerFromBgScript&quot;){
                  console.log(&quot;response from bg script: &quot; + message.data);
              }
      }
  });
  </code></pre>
  <p><strong>background.js:</strong></p>
  <pre><code>chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
  
      var message = request;
      if(message.request === &quot;GetBgScriptStatus&quot;)
      {
          let timeDelay = 4000;
              
          const interval = setTimeout(function(){
              var messageForMainScript = {context: &quot;AnswerFromBgScript&quot;};
              SendMessageToMainScript(messageForMainScript);
          }, timeDelay);
  
      }
  });
  
  function SendMessageToMainScript(messageForMainScript)
  {  
      // Send message to content script
      chrome.tabs.query(
          {active: true, currentWindow: true},
          function(tabs)
          {
              chrome.tabs.sendMessage
              (
                  tabs[0].id,
                  messageForMainScript,
                  function(response)
                  {
                      //console.log(response.farewell)
                  }
              )
              
          }
      )
      // .END (Send message to content script)
      
  }
  </code></pre>