title: Recaptcha - Script tag injection failing sporadically
body: <p>I have a form which uses reCAPTCHA. For some reason, when a user submits this form with an incorrect recapture value, when the page is re-rendered, the recapture fails to render.</p>
  
  <p>What it looks like it happening is that recapture attempts to inject a "script" tag, and sporadically (and only in certain browsers, certain environments, and in certain scenarios), it is failing to add that "script" tag to the DOM.</p>
  
  <p>It happens like this:</p>
  
  <p>1) There is some inline javascript embedded in the form that looks like this:</p>
  
  <pre><code>https://www.google.com/recaptcha/api/challenge?k=&lt;our public key&gt;
  </code></pre>
  
  <p>2) That script executes correctly and returns the following:</p>
  
  <pre><code>var RecaptchaState = {
   site : &lt;some value&gt;,
   challenge : &lt;challenge key&gt;,
   is_incorrect : false,
   programming_error : '',
   error_message : '',
   server : 'https://www.google.com/recaptcha/api/',
   timeout : 18000
  };
  
  document.write('&lt;scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"&gt;&lt;/scr'+'ipt&gt;');
  </code></pre>
  
  <p>3) What typically happens after that, is that the script tag is injected into the page, recaptcha.js is loaded, and it will read RecaptchaState to make a call out to recaptcha to get the image to render.</p>
  
  <p>However, in certain cases, for some reason, the script tag that should be added in 2) never appears to be added to the DOM, so recaptcha.js is never loaded, so the recaptcha is never rendered! I can see in the console after the page is rendered that the "RecaptchaState" exists and has the correct value, just no script tag to go with it. </p>
  
  <p>So that's what is happening and I am really stumped as to why. I am only able to reproduce this in Firefox, and oddly enough, it only happens under certain conditions. For instance, if I am routing requests through fiddler, it will work every time, never fails. If I clear my cache before I submit the request, it will work every time. Sometimes, when I'm expecting it to fail, it works, and vice versa. So it's very sporadic.</p>
  
  <p>So my thought is that maybe it is has something to do with the timing of the js loading which is interfering with the "document.write" statement. Maybe some other javascript is interfering with it or something like that. Just looking for some general ideas as to how I might attempt to figure this out, tests I can run, things I can look for, or any ideas as all really.</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>Update</strong></p>
  
  <p>Still no luck figuring this out. One thought I had ... we see no error messages in the firebug console which would indicate that anything is going awry, although something obviously is. Are there any utilities we could use to get a closer look at exactly what is going on in Firefox? I'm thinking of something like "Speed-Tracer" for Chrome, which gives you a very detailed timeline of events. The only problem here is that we cannot reproduce
  it in Chrome.</p>