Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including recaptcha-frontend with all npm packages installed. Try it out:

var recaptchaFrontend = require("recaptcha-frontend")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

recaptcha-frontend v1.0.1

ES module for the Google reCAPTCHA frontend integration.

Google reCAPTCHA v3 - Frontend Integration

npm npm bundle size (minified)

ES module for the Google reCAPTCHA v3 frontend integration.

Install

$ npm install --save recaptcha-frontend

Usage

Pick your favorite:

const { execute, load } = require("recaptcha-frontend");
import execute, { load } from 'recaptcha-frontend';

... then all you need is:

execute('homepage', 'site-key').then((token) => {
    // Send `token` to your backend for verification.
});

execute() will automatically load the reCAPTCHA v3 API and execute your request in a single step. You can also preload the API and call execute() later, without specifying your site key on every call:

load('site-key').then(() => {
    // The API is loaded and ready.
});

// Do other things ...

execute('homepage').then(token => {
    // Send `token` to your backend for verification.
});

API

load(siteKey, [recaptchaNet = false])

Returns: (Promise) The fulfillement handler (then) is called when the API is loaded and ready.

Loads the API.

execute(action, [siteKey], [recaptchaNet = false])

  • action (string) The action to execute.
  • siteKey (string) Your reCAPTCHA site key. If not specified, will use the last site key provided to load() or execute().
  • recaptchaNet (boolean) Whether to use the recaptcha.net alternate URL to load the API.

Returns: (Promise) The fulfillment handler (then) receives a single token parameter that can be used for verification.

Executes an action. Loads the API if needed.

showBadge()

Shows the reCAPTCHA badge.

hideBadge()

Hides the reCAPTCHA badge. This requires the reCAPTCHA branding to be included visibly in the user flow.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free