Mac-Barrett / SvelteKit-ReCaptcha

A simple demo for my Svelte-Kit ReCaptcha component
7 stars 0 forks source link

Error: No reCAPTCHA clients exist #1

Open kermado opened 9 months ago

kermado commented 9 months ago

I get the error "Error: No reCAPTCHA clients exist" when navigating from another page to the page with the reCaptcha. It works fine if I land directly on the reCaptcha page, but not if navigating from another page.

I think the issue is that the reCaptcha script loads before the container has been added to the DOM. It's fixable by loading reCaptcha with the "explicit" flag: https://www.google.com/recaptcha/api.js?render=explicit, and then calling grecaptcha.render("some-container-id") inside onMount().

onMount(function() {
    grecaptcha.ready(function() {
        grecaptcha.render("recaptcha-container");
    });
});
Usman024 commented 7 months ago

Same Issue For me

Usman024 commented 7 months ago

@kermado I am using it like this in my svelte kit project <ReCaptcha bind:this={Captcha} {SITE_KEY} captchaStyle={{ theme: 'dark', size: 'compact' }} />