Developer documentation

JavaScript reference

window.CDPCaptcha

MemberDescription
createWidget(options)Creates a widget on options.element and returns its handle.
attach(root?)Mounts widgets on all .cdp-captcha elements below root (default document) that have none yet. Runs automatically on load unless the script tag has data-manual="1".
getAllWidgets()Array of all live widget handles.
getWidgetById(id)Handle by id, or null.
getWidgetByElement(el)Handle by element, or null.
reset(el?)Resets the widget of that element (or the first widget).
versionVersion string of the script.

Widget handle

MemberDescription
idUnique id of this widget on the page.
sitekeyThe sitekey in use.
startMode"auto", "focus" or "none".
start()Requests a puzzle and starts solving (no-op while solving or completed).
reset()Stops the worker, clears the response, goes back to the start state (starts again in auto mode).
destroy()Removes the widget; the handle is unusable afterwards.
getState()Current state name.
getResponse()The response token, ".ERROR", ".EXPIRED" or an empty string.
getElement()The mount element.
getStats()After solving: { ms, hashes, bits, count, difficulty }.
isDestroyed()true after destroy().
addEventListener(name, fn)Listen to the widget events (same names as the DOM events).
removeEventListener(name, fn)Stop listening.

Script tag attributes

AttributeMeaning
data-manual="1"Do not mount widgets automatically; call CDPCaptcha.attach() or createWidget() yourself.
data-api-endpointDefault API base for all widgets on the page.
data-compatComma list of frc, recaptcha, hcaptcha: also mount on the element classes of those services and name the hidden field like they do. See the migration guide.

Response token

A base64url string of about 150 characters: the 32-byte puzzle header, the 32-byte server signature and eight 8-byte nonces.
It is opaque to your code;
just forward it to siteverify.
Maximum accepted size is 16 KB.