Products
Captcha

Methods

render(container, id, options?)

Renders a CAPTCHA widget in the specified container. This includes three callback functions:

  1. onToken: Called when the CAPTCHA is successfully solved and a token is generated
  2. onError: Called when the CAPTCHA encounters an error during loading or execution
  3. onExpired: Called when a previously generated token has expired and needs to be refreshed
await captcha.render(
    'container-id', // or HTMLElement
    'unique-widget-id',
    {
        size?: 'normal' | 'compact' | 'invisible' | 'flexible'; // flexible only for Turnstile
        startMode?: 'auto' | 'focus' | 'none'; // Friendly Captcha only
        onToken?: (token: string) => void; // Called on frc:widget.complete for Friendly Captcha
        onError?: () => void; // Called on frc:widget.error for Friendly Captcha
        onExpired?: () => void; // Called on frc:widget.expire for Friendly Captcha
    }
);

execute(id)

Programmatically executes an invisible CAPTCHA (triggers the challenge). For Friendly Captcha, this calls the start() method on the widget when startMode is set to 'none'.

await captcha.execute('widget-id');

getToken(id)

Retrieves the token for a solved CAPTCHA.

const token = await captcha.getToken('widget-id');

reset(id)

Resets a CAPTCHA widget to its initial state. For Friendly Captcha, this calls the reset() method on the widget and clears the stored token.

captcha.reset('widget-id');

load()

Manually loads the provider’s script. This is automatically called by render(), but can be called separately for preloading. For Friendly Captcha, this loads the SDK from CDN if not already loaded.

await captcha.load();