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 |
|---|---|
| <var translate="no">container</var> | The HTML element to render the reCAPTCHA widget. Specify either the ID of the container (string) or the DOM element itself. |
| <var translate="no">parameters</var> | An object containing parameters as key=value pairs, for example, `{"sitekey": "your_site_key", "action": "login", "theme": "dark"}`. See [Attributes and parameters](https://docs.cloud.google.com/recaptcha/docs/api-ref-checkbox-keys.md.txt#attributes_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 |
|---|---|
| <var translate="no">widget_id</var> | 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 |
|---|---|
| <var translate="no">widget_id</var> | Optional. Widget ID returned from `grecaptcha.enterprise.render()`. If not specified, it defaults to the ID of the first widget that was created. > [!NOTE] > **Note:** For use with checkbox site keys. |
| <var translate="no">sitekey</var> | Specify the reCAPTCHA site key to be protected. > [!NOTE] > **Note:** For use with score-based site keys. |
| <var translate="no">action</var> | An object with a single key=value pair, where the value for `action` key specifies the action name associated with the protected element. > [!NOTE] > **Note:** For use with score-based site keys. 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

    grecaptcha.enterprise.ready(callback: function): void

#### Parameters

| Parameter | Description |
|---|---|
| <var translate="no">callback</var> | The function to call when the reCAPTCHA library finishes loading. |

#### Return value

Does not return a value.

### grecaptcha.enterprise.getResponse

Gets the response for the reCAPTCHA widget.

#### Syntax

    grecaptcha.enterprise.getResponse(widget_id: number): string

#### Parameters

| Parameter | Description |
|---|---|
| <var translate="no">widget_id</var> | 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

Gets the response of the reCAPTCHA widget. It can be either a string with the
token created by `grecaptcha.enterprise.execute()` or an empty
string if the token has not yet been created.

## Configuration

This section describes the JavaScript resource parameters and the parameters
used by `grecaptcha.enterprise.render()` and attributes of the
`g-recaptcha` widget.

### JavaScript resource (enterprise.js) parameters

The following table lists the parameters of the JavaScript resource (`enterprise.js`)
that you must include when using reCAPTCHA.

For more information about using these parameters, see the examples in
[Rendering the reCAPTCHA widget on the frontend](https://docs.cloud.google.com/recaptcha/docs/instrument-web-pages-with-checkbox.md.txt).

| Parameter | Value | Description |
|---|---|---|
| `onload` | <var translate="no">callback</var> | Optional. The name of your callback function to be executed after all the dependencies have loaded. |
| `render` | **`onload`** | Optional, default value. Renders the widget in the first `g-recaptcha` tag it finds. > [!NOTE] > **Note:** For use with checkbox site keys. |
| `render` | `explicit` | Optional. Does not render the widget automatically. You need to call `grecaptcha.enterprise.render()` to render it programmatically. > [!NOTE] > **Note:** For use with checkbox site keys. |
| `render` | <var translate="no">siteKey</var> | When used with score-based site keys, this parameter is not optional. The value <var translate="no">siteKey</var> specifies the score-based site key associated. > [!NOTE] > **Note:** For use with score-based site keys only; if used with checkbox site keys the script won't load. |
| `hl` | See [language codes](https://docs.cloud.google.com/recaptcha/docs/language.md.txt). | 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 | Allowed values | Default | Description |
|---|---|---|---|---|
| `data-sitekey` | `sitekey` |   |   | reCAPTCHA Key. |
| `data-badge` | `badge` | `bottomright`, `bottomleft`, `inline` | `bottomright` | Optional. Reposition the reCAPTCHA badge. `inline` lets you position it with CSS. |
| `data-action` | `action` |   |   | Optional. String describing current [action](https://docs.cloud.google.com/recaptcha/docs/actions-website.md.txt). |
| `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` | Integer | 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` | String | N/A | 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` | String | N/A | 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` | String | N/A | Optional. The name of your callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. The callback does not receive any arguments containing error details. If you specify a function here, you are responsible for informing the user that they should retry. |