
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@beyowi/svelte-recaptcha-v2
Advanced tools
Google ReCaptcha v2 implementation for Svelte and SvelteKit

Google reCAPTCHA v2 implementation for Svelte SPA, SSR and sveltekit static sites.
# install as a development dependency
pnpm install -D svelte-recaptcha-v2
Import the library onto your template and update your google key:
import { Recaptcha, recaptcha, observer } from "svelte-recaptcha-v2";
/*
│Recaptcha: svelte <Recaptcha> component.
│recaptcha: google method, gives you recaptcha.execute().
│observer: allows you to track captcha state across components.
*/
const googleRecaptchaSiteKey="replace_with_yours";
In your form, add the component:
<Recaptcha
sitekey={googleRecaptchaSiteKey}
badge={"top"}
size={"invisible"}
on:success={onCaptchaSuccess}
on:error={onCaptchaError}
on:expired={onCaptchaExpire}
on:close={onCaptchaClose}
on:ready={onCaptchaReady} />
Setup your event handlers:
const onCaptchaReady = (event) => {
console.log("recaptcha init has completed.")
/*
│You can enable your form button here.
*/
};
const onCaptchaSuccess = (event) => {
userTracker.resolve(event);
console.log("token received: " + event.detail.token);
/*
│If using checkbox method, you can attach your
│form logic here, or dispatch your custom event.
*/
};
const onCaptchaError = (event) => {
console.log("recaptcha init has failed.");
/*
│Usually due to incorrect siteKey.
|Make sure you have the correct siteKey..
*/
};
const onCaptchaExpire = (event) => {
console.log("recaptcha api has expired");
/*
│Normally, you wouldn't need to do anything.
│Recaptcha should reinit itself automatically.
*/
};
const onCaptchaOpen = (event) => {
console.log("google decided to challange the user");
/*
│This fires when the puzzle frame pops.
*/
};
const onCaptchaClose = (event) => {
console.log("google decided to challange the user");
/*
│This fires when the puzzle frame closes.
│Usually happens when the user clicks outside
|the modal frame.
*/
};
Update your form handler:
const submitHandler = async () => {
console.log("launching recaptcha");
recaptcha.execute();
console.log("pending for google response");
const event = await Promise.resolve(observer);
const recaptchaToken = event.detail?.token ? event.detail.token : false;
if (!recaptchaToken) {
console.log("recaptcha is NOT OK");
return false;
}
console.log("token retrieved", recaptchaToken);
};
If you would like to enable client side debugging, add {Recaptcha} value to your localStorage DEBUG key.
If any trouble, please create an issue. PRs are most welcome.
FAQs
Google ReCaptcha v2 implementation for Svelte and SvelteKit
We found that @beyowi/svelte-recaptcha-v2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.

Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.

Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.