Developer documentation

Events and lifecycle

The widget emits DOM events on its element.
They bubble, so you can also listen on the form or on document.
The same events are available through widget.addEventListener().

JavaScript
const el = document.querySelector('.cdp-captcha');
const button = document.querySelector('#send');
button.disabled = true;

el.addEventListener('cdpcaptcha:widget.complete', (ev) => {
  console.log('response', ev.detail.response);
  button.disabled = false;
});
el.addEventListener('cdpcaptcha:widget.error', (ev) => {
  console.warn('captcha error', ev.detail.error.code);
  button.disabled = false; // let the visitor submit; your server decides
});
el.addEventListener('cdpcaptcha:widget.expire', () => { button.disabled = true; });

Events

EventWhen
cdpcaptcha:widget.completeThe check passed. detail.response holds the token for your server.
cdpcaptcha:widget.errorSomething failed (network, sitekey, rate limit). detail.error.code says what. The visitor can click to retry.
cdpcaptcha:widget.expireThe completed response expired because the page stayed open too long. The visitor can click to restart.
cdpcaptcha:widget.resetreset() was called.
cdpcaptcha:widget.statechangeAny state change; detail.state is the new state.

Every event carries detail = { name, state, response, id, error }.
error is null unless the state is error;
then it is { code, detail }.

States

StateMeaning
initWidget object created, element not rendered yet.
unactivatedRendered, waiting for a start (click, focus, auto or start()).
requestingFetching a puzzle from the server.
solvingThe Web Worker is computing; the progress bar moves.
solvedOne-click mode only: solved, waiting for the click.
completedDone. The hidden field holds the response.
expiredThe response is no longer valid; the hidden field holds ".EXPIRED".
errorFailed; the hidden field holds ".ERROR".
resetAfter reset(); behaves like unactivated.
destroyedAfter destroy(); the element is empty and the widget cannot be used again.

Error codes

CodeMeaning
network_errorThe browser could not reach the API.
sitekey_missingThe element has no sitekey.
sitekey_invalidUnknown or revoked sitekey, or the page origin is not allowed for it.
rate_limitedThis address requested too many puzzles in a short time.
otherAnything else; detail has a short description.