title: Javascript to decode the google recaptcha with anti-captcha
body: <p>I am a beginner in non-proffetional programming just a passion.</p>
  <p>I made a code in javascript to decode the google recaptcha with anti-captcha.
  the code received does not work on the google page.
  I get the answer with the code, but I don't know if it's the javascript that is badly written or the submit button that is bad.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>setTimeout(recaptchaFunction, 1000);
  
  function recaptchaFunction() {
      document.getElementById('g-recaptcha-response').style.display = 'inline-block';
      document.getElementById('g-recaptcha-response').style.visibility = 'visible';
      document.getElementById('g-recaptcha-response').style.height = '200px';
      document.getElementById('g-recaptcha-response').style.width = '900px';
      document.getElementById('g-recaptcha-response').style.resize = 'auto';
      var elem = document.getElementById('recaptcha');
      var sitekey = elem.getAttribute('data-sitekey');
      var attempts = 1;
      setTimeout(
          createTask(sitekey), 
      2000);
      
      function createTask(sitekey) {
          var apikey = "7k20d71gf7138605ffe3729806c9efgt";
          var domain = "google.fr";
          var secret = "6LfI9IsUAAAAAAzPsrgGKsQVlfnRs8OYeOmdxd-Q";
          seconds = 0;
          payload = {
              'clientKey' : apikey,
              'task' : {
                  "type":"NoCaptchaTaskProxyless",
                  "websiteURL":"http:\/\/"+domain+"\/",
                  "websiteKey":sitekey
              }
          };
          var xhr = new XMLHttpRequest();
          var url = "url";
          xhr.open("POST", 'https://api.anti-captcha.com/createTask', true);
          xhr.setRequestHeader("Content-Type", "application/json");
          var taskId = "";
          xhr.onreadystatechange = function () {
              if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
                  var json = JSON.parse(xhr.responseText);
                  console.log(json);
                  if (json.errorId == 0) {
                      setTimeout(function () {
                          taskId = json.taskId;
                          getTaskResult(taskId, apikey);
                      }, 2000);
                  }
              }
          };
          var data = JSON.stringify(payload);
          xhr.send(data);
          return true;
      }
      
      function getTaskResult(taskId, apikey) {
          payload = {
              'clientKey' : apikey,
              'taskId' : taskId
          };
          var xhr = new XMLHttpRequest();
          var url = "url";
          xhr.open("POST", 'https://api.anti-captcha.com/getTaskResult', true);
          xhr.setRequestHeader("Content-Type", "application/json");
          xhr.onreadystatechange = function () {
              if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
                  var json = JSON.parse(xhr.responseText);
                  console.log(json);
                  if (json.errorId == 0) {
                      if (json.status == 'ready') {
                          document.getElementById('g-recaptcha-response').innerHTML = json.solution.gRecaptchaResponse
                          document.getElementById('captcha-form').submit();
                          //alert(json.solution.gRecaptchaResponse);
                          } else {
                          attempts ++;
                          setTimeout(getTaskResult(taskId, apikey), 2000);
                      }
                      }
              }
          };
          var data = JSON.stringify(payload);
          xhr.send(data);
      }
  }</code></pre>
  </div>
  </div>
  </p>