title: Tampermonkey get table in an iframe?
body: <p>I'm trying to enhance a GUI of one of our tools, but I'm failing miserably. The UI consists of a body with multiple iFrames from which I want to select one and change the content a bit.</p>
  
  <p>The problem is that when using my selector <code>frame = $("iframe[src*='/vs/virt.jsp']");</code> it looks like it can't find the element.</p>
  
  <p>Here's the code (doesn't do anything else than log):</p>
  
  <pre><code>// ==UserScript==
  // @name UI Tweaks
  // @version 0.2
  // @description Does stuff
  // @match https://*.local/vs/*
  // @run-at          document-end
  // @grant none
  // @require http://code.jquery.com/jquery-latest.js
  // ==/UserScript==
  
  
  console.log(window.location);
  console.log("before");
  console.log($());
  frame = $("iframe[src*='/vs/virt.jsp']");
  console.log(frame.attr("id"));
  console.log("after");
  </code></pre>
  
  <p>When running this on the page I get two page loads and it shows the location object, before and after. But the frame object is totally empty.</p>
  
  <p>However, when running the same thing in Chrome developer console after the page has loaded I get the elements I'm looking for.</p>
  
  <p>I've tried different ways to only load the script after page load etc, but it still does not work. </p>
  
  <p>Update:</p>
  
  <p>I added:</p>
  
  <pre><code>// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
  </code></pre>
  
  <p>Then tried this:</p>
  
  <pre><code>waitForKeyElements (
      "iframe[src*='/vs/virt.jsp']",
      test()
  );
  
  function test(){
      frame = $("iframe[src*='/vs/virt.jsp']");
      console.log(frame.attr("id"));
  }
  </code></pre>
  
  <p>Still the same result. Worth noting is that I use Tampermonkey, but perhaps it's the same?</p>
  
  <p>Edit 2:</p>
  
  <pre><code>function timer() {
    frame = $("iframe[src*='/vs/virt.jsp']");
      console.log(frame.attr("id"));
      setTimeout(timer, 1000);
  }
  
  timer();
  </code></pre>
  
  <p>It keeps outputting "undefined" whereas if I try it in Chrome developer console I get the object. It's like Tampermonkey does not have access?</p>