checkGoogleReCaptchaInjected

checkGoogleReCaptchaInjected

Checks if Google reCAPTCHA script is already injected in the document

Import

import { checkGoogleReCaptchaInjected } from '@google-recaptcha/core';

Usage

checkGoogleReCaptchaInjected();

Return

Returns true if the reCAPTCHA script is already injected, false otherwise.

Examples

Basic

if (checkGoogleReCaptchaInjected()) {
  console.log('Script already loaded');
}

With Script Loading

if (!checkGoogleReCaptchaInjected()) {
  injectGoogleReCaptchaScript({
    render: 'explicit',
    onload: () => console.log('Script loaded')
  });
}

With Cleanup

if (checkGoogleReCaptchaInjected()) {
  removeGoogleReCaptchaScript();
}

Details

Script Detection

Checks for:

  • Script tags with reCAPTCHA source
  • Excludes gstatic resources
  • Both standard and enterprise versions

Performance

  • Synchronous operation
  • DOM query based
  • No network requests

See Also

Last updated on