Skip to content

Add to your Agent

Widget configuration ​

This reference targets the CDN API exposed as window.katcha, not the native package factory API. Obtain your deployed widget URL from your operator.

Katcha container configuration ​

HTML attributeRender optionValues and behavior
data-site-keysite_keyRequired public site key
data-sizesizenormal (default) or invisible
data-themethemelight (default) or dark
data-colorcolorOptional color name or hex code
data-error-printerror_print0 shows inline errors (default); 1 hides them
data-langlangUse en for English; implementation default is fa
data-callbackcallbackSuccess; receives the token string
data-rendered-callbackrendered_callbackWidget rendered
data-blocked-callbackblocked_callbackChallenge blocked
data-error-callbackerror_callbackReceives legacy { code, message } errors
data-reset-callbackreset_callbackReset notification; public reset() does not emit it
data-expired-callbackexpired_callbackToken expired
data-chlexpired-callbackchlexpired_callbackChallenge expired
data-clicked-callbackclicked_callbackCheckbox clicked or execution started
data-opened-callbackopened_callbackChallenge opened
data-closed-callbackclosed_callbackChallenge closed

For automatic rendering, callback names must resolve to functions on window. For explicit rendering, pass functions or global function names. Success callbacks receive a string, unlike the object returned by execute().

html
<div class="katcha" data-site-key="YOUR_SITE_KEY" data-lang="en"
     data-theme="dark" data-callback="onSolved"></div>
<script>
  window.onSolved = function (token) {
    document.getElementById('captcha-status').textContent = token ? 'Challenge completed.' : '';
  };
</script>

Provide a status element and load your deployment's widget script after defining callbacks. A completion message is not authorization: verify on the server.

JavaScript API ​

The following methods belong to the CDN/SDK public API. Reset, token retrieval, and execution target the first widget when the widget ID is omitted. Pass an explicit ID when a page contains more than one widget.

katcha.render(container, params) ​

Renders a widget and returns a string widget ID. Supply a CSS selector (for example, #captcha) or element, and options from the table above. The native package's createKatcha() interface returns a widget handle instead; do not mix the APIs.

katcha.reset(widgetID) ​

Resets the selected widget and clears its token. Returns undefined without invoking reset_callback. Use it to prepare a fresh attempt, not to reuse tokens.

katcha.getKatchaToken(widgetID) ​

Returns the current token, or no usable token before success or after reset. The old getArcToken name is not a Katcha alias.

katcha.execute(widgetID) ​

Starts the workflow, normally on an invisible widget. Await its promise and handle rejection, including dismissal and expiration. Success resolves to { katcha_token, site_key }; success callbacks still receive only a token string.

js
try {
  const { katcha_token } = await window.katcha.execute(widgetId);
  if (katcha_token) {
    document.getElementById('protected-form').requestSubmit();
  }
} catch (error) {
  document.getElementById('captcha-status').textContent = 'Please try again.';
}

Here widgetId must be the ID returned by render. Do not use this pattern in a submit handler that recursively invokes itself through requestSubmit().

Explicitly render Katcha ​

Use a container without the .katcha discovery class. Render only after the script loads; an asynchronous script is not necessarily ready for adjacent code. Replace the .example script host with your deployed Katcha host.

html
<form id="protected-form" action="/protected-action" method="post">
  <div id="captcha"></div>
  <p id="captcha-status" role="status"></p>
  <button type="submit">Continue</button>
</form>
<script>
  window.initializeCaptcha = function () {
    window.protectedWidgetId = window.katcha.render('#captcha', {
      site_key: 'YOUR_SITE_KEY',
      lang: 'en',
      theme: 'light'
    });
  };
</script>
<script src="https://widget.katcha.eu/1/api.js" defer onload="initializeCaptcha()"></script>

This uses the script element's onload, not an assumed ?onload= query contract. Do not render the same element both explicitly and through automatic discovery.

Error handling (client-side) ​

Set data-error-callback="onCaptchaError" and define the function before loading the script. Provide a status element and a retry path without logging tokens.

js
window.onCaptchaError = function ({ code, message }) {
  document.getElementById('captcha-status').textContent =
    `Challenge failed (${code}). Please try again.`;
};
Legacy codeMeaning
101Challenge creation server error
102Challenge creation network error
201Answer server error
202Answer network error
203Incorrect answer
401Unknown-error conversion fallback; not emitted by the legacy error callback

The legacy callback does not report all rejected executions. Handle the promise separately for dismissal, blocked challenges, and expiration. Client errors are not server verification error codes.

Integration testing: test keys ​

No bot protection

The built-in test key bypasses challenge requests. Never use it on production forms or treat its deterministic token as proof of a real challenge.

Test key set ​

Widget test valueDefault
Site key0000000000
Generated token000000000000000000000000000000

These widget defaults are configurable at build time and test browser integration only. The source documentation's test secret is not verified against the Katcha verification deployment and is not published here. Use a mocked verification service for automated application tests, or operator-approved staging credentials for end-to-end checks.