title: Chrome KeyLogger (for Educational purposes)
body: <p>I am trying to develop a Chrome keylogger for educational purposes. The problem I am facing is that I am not sure how to capture the keys from different tabs. I have created a extension for the keylogger with a icon. When the icon is pressed; the background page is supposed to run and just alert the key string as they are pressed.</p>
  <p>The code of the background page is:</p>
  <pre><code>&lt;script&gt;
      chrome.browserAction.onClicked.addListener(currWin);
      document.onmousedown = currWin;
  function getCurrWin()
  {
      chrome.tabs.getCurrent(currWin);
  }
  
  function currWin(tab)
  {
      chrome.tabs.getSelected(null,function(tab){
      alert(tab.title + &quot; : &quot; + tab.id);
      document.onkeypress = keylogger;
  })
  }
  
  function keylogger(e)
  {   if(e.keyCode==27)
      {
          alert('A');
      }
      else{
      logged_keys+=String.fromCharCode(e.charCode);
      alert(logged_keys);
  }}
  &lt;/script&gt;
  </code></pre>