title: javascript google chrome extension iframe cannot examine contentWindow
body: <p>I am writing a Google Chrome extension.  Now I need to examine the contents of an iframe but the content script seems unable to access this content even though the debugger can.  The iframe contents are a list of messages I have previously sent to that site.  If I put the following statement in the content script, it always returns null:</p>
  
  <pre><code>document.getElementById("td_messages_show").getElementsByTagName("iframe")[0].contentWindow.document;
  </code></pre>
  
  <p>But if I open the debugger and execute the same command from the command line, it returns "Document" with the appropriate contents.  At first I thought it was because the frame wasn't finished loading so I found a snippet like this and tried to use it.</p>
  
  <pre><code>function wait4Iframe2Load() {
     // Get a handle to the iframe element
     //console.log('Checking for null myFrame');
      var myFrame = document.getElementById("td_messages_show").getElementsByTagName("iframe")[0].contentWindow;
      if (myFrame!=null) 
      {
          console.log(myFrame);
         // Check if loading is complete
         if ( myFrame.document.readyState == 'complete' ) {
            // The loading is complete, call the function we want executed once the iframe is loaded
            console.log('Loading Complete');
            //frameContent=document.getElementById("td_messages_show").getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName('tbody')[0];
            return;
         }
         else alert(" Frame is Not Loaded");
      }
      else myFrame = document.getElementById("td_messages_show").getElementsByTagName("iframe")[0].contentWindow;
     // If we are here, it is not loaded. Set things up so we check the status again in 100 milliseconds
     console.log('Waiting for frame to load...');
     window.setTimeout('wait4Iframe2Load()', 100);      
  }
  </code></pre>
  
  <p>This simply returns null forever.  But while this script is piling up console messages, I can open the debugger and execute the very same command line and it returns a document.  Faced with this problem and researching internet answers, it seems it may be some deliberate kind of security issue.  Whether it is or isn't, I need to examine the iframe contents and determine what I have written there previously so I can decide what to write there next.</p>
  
  <p>Does anybody have an idea how to solve this problem?</p>