I'm writing a Chrome extension. I'm trying to get my script to open a new tab and enter text in the search, but I am having problems with synchronization it seems. Here is my code:
helloworld.html:
<html>
  <h1 id="test"></h1>
  <head>
  <script src="navigate.js"></script>
  </head>
</html>
manifest.json
{
  "name": "Sonic",
  "version": "0.1",
  "manifest_version": 2,
  "description": "My first Chrome extension.",
  "permissions": [ "tabs" ],
  "browser_action": {
    "default_icon": "Sonic_Sprite.png",
    "default_popup": "helloworld.html"
  },
  "content_scripts": [
    {
      "matches": ["http://stackoverflow.com/questions/*/*"],
      "js": ["jquery-1.11.3.js", "content.js"]
    }
  ]
}
content.js
var raw_title = document.getElementsByClassName("question-hyperlink")[0];
var kickass = window.open("https://kickass.unblocked.pe/");
$(kickass.document).ready( function() {
    kickass.alert("hello");
    var s = kickass.document.getElementById("contentSearch");
    alert(s);
});
I am getting unpredictable behavior from jquery's ready() function. Maybe 20% of the times I load the page it gives me an alert.
Is this a common error, and if so what can be done to fix it? I played around with onload before moving on to jquery, and it produced even worse results in terms of triggering the alert.
 
     
    