title: How to make tab and window active when result is found?
body: <p>I want to bring the tab the extension is running on to the front of my window as soon as the match is found, even if I am currently working in a second window.</p>
  
  <p>So far I have this code in my <strong>content_script.js</strong>, but it doesn't seem to work.
  The  commented lines were my last failed tries.</p>
  
  <p>The alert gave me <strong>-1</strong>, which seems to be quite the weird tab id.</p>
  
  <pre><code>if(output == 'found') {
      sendResponse({findresult: "yes"});
  
      chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
          //chrome.tabs.update(sender.tab.id, {selected: true});
          //chrome.tabs.update(sender.tab.id, {active: true});
          alert(sender.tab.id);
      });
  }
  </code></pre>
  
  <p>I've tried some things in the <strong>background.html</strong> too and all kinds of things already posted here, all with no luck.</p>
  
  <p>What do I need to do to make this work?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>manifest.json</strong> script inclusion</p>
  
  <pre><code>"background": {
      "scripts": ["background.js"]
  },
  "content_scripts": [ {
      "all_frames": false,
      "js": [ "jquery.js", "content_script.js" ],
      "matches": [ "http://*/*", "https://*/*" ],
      "run_at": "document_idle"
  }
  </code></pre>
  
  <p><strong>background.js</strong> (the alert won't even show up)</p>
  
  <pre><code>alert("here");
  
  chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
      your_tab_Id = sender.tab.id);
  });
  
  chrome.tabs.update(your_tab_Id,{"active":true,"highlighted":true},function (tab){
      console.log("Completed updating tab .." + JSON.stringify(tab));
  });
  </code></pre>
  
  <p><strong>content_script.js</strong> jQuery change background (sendResponse works, but if I activate the background changing line the script stops working)</p>
  
  <pre><code>if(found === true) {
              //$('td:contains('+foundItem+')').css("background", "greenyellow");
              sendResponse({findresult: "yes"});
          }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/bZKpq/2/" rel="nofollow">jsFiddle I tested the jQuery code in</a></p>
  
  <p>EDIT 2
  <a href="http://www.mediafire.com/?vmlnwzx8aqqge8g" rel="nofollow">extension download</a></p>