invisible-grecaptcha
Invisible reCAPTCHA integration
Table of Contents
Install
This project uses node and npm.
Go check them out if you don't have them locally installed.
$ npm install --save invisible-grecaptcha
The UMD build is also available on jsdelivr:
<script src="https://cdn.jsdelivr.net/npm/invisible-grecaptcha/dist/index.min.js"></script>
You can find the library on window.invisibleGrecaptcha
.
Usage
import {
createInvisibleGrecaptcha,
execute,
reset,
getResponse,
} from 'invisible-grecaptcha'
function verifyCallback(token) {
console.log(token)
}
const grecaptcha = await createInvisibleRecaptcha({
sitekey: 'RECAPTCHA_SITE_KEY',
callback: verifyCallback
})
execute(grecaptcha)
reset(grecaptcha)
getResponse(grecaptcha)
API
Table of Contents
createInvisibleGrecaptcha
Create an invisible grecaptcha and returns the id of the capctha.
Parameters
options
Object The options to create a invisible recaptcha.
options.sitekey
string Your recaptcha sitekey.options.callback
verifyCallback Captcha callback.options.locale
string? Language of the captcha. See available language codes https://developers.google.com/recaptcha/docs/language. Auto-detects the user's language if unspecified. (optional, default null
)options.position
string Position the reCAPTCHA badge. Values: bottomright, bottomleft and inline. (optional, default bottomright
)options.container
HTMLElement? Container where the captcha will be renderedd. If none is provided a empty div will be create on the body. (optional, default createContainer()
)
Returns number
execute
Programatically invoke the reCAPTCHA check.
Parameters
recaptchaId
number Captcha id.
reset
Resets the reCAPTCHA widget.
Parameters
recaptchaId
number Captcha id.
getResponse
Gets the response for the reCAPTCHA widget.
Parameters
recaptchaId
number Captcha id.
Returns string
verifyCallback
Callback to be executed when the user submits a successful CAPTCHA response.
Type: Function
Parameters
Contributing
See the contributing file.
License
MIT License © Thiago Santos