JavaScript API reference for reCAPTCHA Enterprise

This page describes methods of the reCAPTCHA Enterprise JavaScript API and their configuration parameters that you can use to render the web pages with a checkbox site key.

JavaScript API

The following table lists the methods of the reCAPTCHA Enterprise JavaScript API.

Method Description
grecaptcha.enterprise.render(
container,
parameters
)

Renders the container as a reCAPTCHA widget and returns the ID of the newly created widget.

container

The HTML element to render the reCAPTCHA widget. Specify either the ID of the container (string) or the DOM element itself.

parameters

An object containing parameters as key=value pairs, for example, {"sitekey": "your_site_key", "theme": "light"}.

grecaptcha.enterprise.reset(
opt_widget_id
)

Resets the reCAPTCHA widget.

opt_widget_id

  Optional widget ID, defaults to the first widget created if unspecified.
grecaptcha.enterprise.getResponse (
opt_widget_id
)

Gets the response for the reCAPTCHA widget.

opt_widget_id

Optional widget ID, defaults to the first widget created if unspecified.

Configuration

JavaScript resource (enterprise.js) parameters

The following table lists the parameters of the JavaScript resource (enterprise.js) that you can use to render a widget automatically or explicitly on a web page.

Parameter Value Description
onload Optional. The name of your callback function to be executed once all the dependencies have loaded.
render

explicit

onload

Optional. Whether to render the widget explicitly. Defaults to onload, which renders the widget in the first g-recaptcha tag it finds.

For more information about using these parameters, see the examples in Rendering the reCAPTCHA widget on the frontend.

hl See language codes. Optional. Forces the widget to render in a specific language. Auto-detects the user's language if unspecified.

g-recaptcha tag attributes and grecaptcha.enterprise.render parameters

The following table lists the g-recaptcha tag attributes and the corresponding grecaptcha.enterprise.render() parameters.

g-recaptcha tag attribute grecaptcha.enterprise.render parameter Value Default Description
data-sitekey sitekey reCAPTCHA Key.
data-action action Optional. String describing current action. Currently not supported.
data-theme theme dark light light Optional. The color theme of the widget.
data-size size compact normal normal Optional. The size of the widget.
data-tabindex tabindex 0 Optional. The tabindex of the widget and challenge. If other elements in your page use tabindex, it should be set to make user navigation easier.
data-callback callback Optional. The name of your callback function, executed when the user submits a successful response. The g-recaptcha-response token is passed to your callback.
data-expired-callback expired-callback Optional. The name of your callback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
data-error-callback error-callback Optional. The name of your callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry.