Documentation

Widget methods and events

Use solve(), reset(), and lifecycle events to connect HumanProof to custom form flows.

Methods

The custom element exposes a small JavaScript API for explicit form control.

MethodReturnsPurpose
solve()Promise<{ success: boolean, token: string }>Starts solving, reuses an in-flight solve, or returns the existing token result.
reset()voidClears the current token, resets the hidden field, and returns the widget to idle.

Events

EventDetailWhen it fires
solve{ token }A challenge was solved and the hidden field was filled.
progressChallenge progress payloadThe underlying challenge runtime reports solving progress.
errorError payload or reasonSolving failed, billing blocked the request, the limit was reached, or the widget fallback reported a load failure.
reset{}The widget was reset and the hidden field was cleared.
expired{}The token expired after data-expire-after and must be solved again.
const widget = document.querySelector('human-proof');

widget.addEventListener('solve', (event) => {
  console.log(event.detail.token);
});

widget.addEventListener('expired', () => {
  submit.disabled = true;
});

widget.addEventListener('error', (event) => {
  console.warn(event.detail);
});

Global events

The script dispatches humanproof:ready when the custom elements are registered and humanproof:failed when the browser cannot initialize the runtime.

window.addEventListener('humanproof:ready', (event) => {
  console.log(event.detail.version);
});

window.addEventListener('humanproof:failed', (event) => {
  console.warn(event.detail.reason);
});

Watchdog

HumanProof.watchdog() can show a plain fallback message if a consent manager, browser extension, or corporate gateway prevents the widget from initializing.

<script>
window.addEventListener('humanproof:ready', () => {
  window.HumanProof.watchdog({ timeout: 3000 });
});
</script>