JavaScript API reference for reCAPTCHA

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

reCAPTCHA JavaScript API methods

This section describes the syntax and parameters of reCAPTCHA JavaScript API methods.

grecaptcha.enterprise.render

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

Syntax

grecaptcha.enterprise.render(container: string | HTMLelement, parameters: Object): number

Method Parameters

Parameter Description
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", "action": "login", "theme": "dark"}.

See Attributes and parameters for details about each configurable parameter.

Return value

Returns the ID of the newly created widget.

grecaptcha.enterprise.reset

Resets the reCAPTCHA widget.

Syntax

grecaptcha.enterprise.reset(widget_id: number): void

Parameters

Parameter Description
widget_id Optional. Widget ID returned from grecaptcha.enterprise.render(). If not specified, it defaults to the ID of the first widget that was created.

Return value

Does not return a value.

grecaptcha.enterprise.execute

Programmatically invokes the reCAPTCHA verification.

Syntax

grecaptcha.enterprise.execute(widget_id: number): Promise<string>
grecaptcha.enterprise.execute(sitekey: string, action: Object): Promise<string>

Parameters

Parameter Description
widget_id Optional. Widget ID returned from grecaptcha.enterprise.render().

If not specified, it defaults to the ID of the first widget that was created.

sitekey

Specify the reCAPTCHA site key to be protected.

action An object with a single key=value pair, where the value for action key specifies the action name associated with the protected element.

For example: {"action": "action_name"}

Return value

If successful, returns a Promise object containing the token if successful.

grecaptcha.enterprise.ready

Runs your function when the reCAPTCHA JavaScript library loads.

Syntax