title: Recaptcha v2 throws an error when it is reset and its container element is removed from DOM
body: <p>When I explicitly render Recaptcha v2 and then reset it before removing it from the DOM, after ~40 seconds I get an error in the browser console.</p>
  <p>I have a <a href="https://jsfiddle.net/v5qLw7b4/" rel="nofollow noreferrer">JSFiddle</a> which can be used to reproduce the issue.</p>
  <p>Here's the relevant code excerpt:</p>
  <pre><code>const recaptchaHolder = document.getElementById('...');
  const recaptchaWidgetId = grecaptcha.render(recaptchaHolder, {/*...*/});
  // then later
  grecaptcha.reset(recaptchaWidgetId);
  recaptchaHolder.parentElement.removeChild(recaptchaHolder);
  </code></pre>
  <p>The error that I get is:</p>
  <blockquote>
  <p>Uncaught (in promise) Timeout</p>
  </blockquote>
  <p>with the following stacktrace (the actual stacktrace might vary since it happens in heavily minified code):</p>
  <pre><code>setTimeout (async)      
  J           @   recaptcha__en.js:100
  (anonymous) @   recaptcha__en.js:285
  tb          @   recaptcha__en.js:284
  mj          @   recaptcha__en.js:456
  (anonymous) @   recaptcha__en.js:458
  </code></pre>
  <p>I've tried to utilize the <code>'error-callback'</code> parameter from <a href="https://developers.google.com/recaptcha/docs/display" rel="nofollow noreferrer">the documentation</a> to catch this error, but that did not help - the error is still uncaught, and this callback does not get invoked.</p>
  <p>Another observation: if I omit calling <code>grecaptcha.reset</code> before removing the element from the DOM, then the error does not happen. <strong>However</strong>, it might result in inconsistent UI: if the user is challenged by recaptcha (for example, using images), and the element is simply removed from DOM without calling <code>grecaptcha.reset</code>, then the challenge HTML is not cleaned up from the DOM.</p>
  <p>I'm looking for ways of either handling the above mentioned error, or handling recaptcha removal in a different way (if I am doing it wrong now)</p>
  <p><strong>UPDATE (June 24th 2022)</strong>: This is still happening.</p>