Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vanilla-hcaptcha

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vanilla-hcaptcha

Vanilla Web Component for hCaptcha. 0 dependencies. <1kb gzipped.

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
224
decreased by-44.55%
Maintainers
1
Weekly downloads
 
Created
Source

hCaptcha - Vanilla Web Component

0 dependencies. <1kb gzipped. Integrates well with Vue.JS.

Install

yarn add vanilla-hcaptcha
<script src="https://cdn.jsdelivr.net/npm/vanilla-hcaptcha"></script>

Usage Vue.JS

main.js

Import once in application. Ignore the custom element.

import "vanilla-hcaptcha";

Vue.config.ignoredElements = [
  "h-captcha"
];
Integrate in your component
<template>
    ...
    <h-captcha id="signupCaptcha"
               site-key="10000000-ffff-ffff-ffff-000000000001"
               size="normal"
               dark
               tabindex="0"
               @loaded="onCaptchaLoaded"
               @verified="onCaptchaVerified"
               @expired="onCaptchaExpired"
               @error="onCaptchaError" />
</template>

export default {
    name: ...
    methods: {
        onCaptchaLoaded(e) {
          console.log("Captcha is loaded");
          e.target.render(); // Show captcha
        },
        onCaptchaVerified(e) {
          console.log("Captcha is verified", { key: e.key });
        },
        onCaptchaExpired() {
          console.log("The verified captcha expired");
        },
        onCaptchaError(e) {
          console.log("Captcha error", { error: e.error });
        }
    }
}

Usage Vanilla.JS

<h-captcha id="signupCaptcha"
           site-key="10000000-ffff-ffff-ffff-000000000001"
           size="normal"
           dark
           tabindex="0" />

const signupCaptcha = document.getElementById('signupCaptcha');

signupCaptcha.addEventListener('loaded', () => {
    signupCaptcha.render(); // Show captcha
});
signupCaptcha.addEventListener('verified', (e) => {
    console.log('verified event', { key: e.key });
});
signupCaptcha.addEventListener('expired', () => {
    console.log('expired event');
});
signupCaptcha.addEventListener('error', (e) => {
    console.log('error event', { error: e.error });
});

Docs

It loads hcaptcha.min.js if not already present on dom.

Attributes
AttributeDescription
site-keyThe site key generated in hCaptcha dashboard.
sizeOne of: normal, compact, invisible
darkTo use the dark theme
tabindexSet the tabindex of the hCaptcha popup.
Events
EventDataDescription
loadednullEmitted when component is ready to show captcha. This is necessary if window.hcaptcha is not already in the dom.
verifiedkey - verification key to be checked on backend sideEvent emitted after captcha was successfully verified.
expirednullEmitted when a captcha was verified but it expired.
errorerrorEmitted when an error happened.

Develop & Test

yarn build
yarn test

Keywords

FAQs

Package last updated on 05 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc