title: Uncaught TypeError: Cannot read property 'getSelected' of undefined (Chrome-Extension )
body: <p>Hi i am making google chrome extension and stucked with error</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'getSelected' of undefined 
  </code></pre>
  
  <p>My code is below</p>
  
  <p>called function  getQueryString(); inside if statement is creating error</p>
  
  <p>key_event.js</p>
  
  <pre><code>if (window == top) {
  window.addEventListener('keyup', doKeyPress, false); //add the keyboard handler
  
  }
    trigger_key = 37; 
       function doKeyPress(e){
       if (e.ctrlKey &amp;&amp; e.keyCode == 37)
       { 
              alert("leftpressed");
              getQueryString();
      }
      else if(e.ctrlKey &amp;&amp; e.keyCode == 39){ // if e.shiftKey is not provided then script will run at all instances of typing "G"
           alert("rightpressed");
  
          getQueryString();
      }
      }
  
      function getParameterByName(name,urlPara) {
      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
      var regex = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)"),
      results = regex.exec(urlPara);
      return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  
   function getQueryString() {
            chrome.tabs.getSelected(null, function(tab) {
            var tab = tab.url;
            var queryString = {};
            var substr = tab.replace(
            new RegExp("([^?=&amp;]+)(=([^&amp;]*))?", "g"),
            function($0, $1, $2, $3) { queryString[$1] = $3; }
        );  
        var current = getParameterByName('page',tab);
           var reExp = 'page=' + current;
           current = parseInt(current, 10)-1;
          var newUrl = tab.replace(reExp, 'page=' + current);
          console.log(newUrl);
          chrome.runtime.sendMessage({redirect: newUrl});
      });
  }
  </code></pre>
  
  <p>help can bring cheers</p>