Skip to content

Instantly share code, notes, and snippets.

@andreasnuesslein
Created April 25, 2024 16:01
Show Gist options
  • Save andreasnuesslein/c3eb4b162561686ad739837e1495be84 to your computer and use it in GitHub Desktop.
Save andreasnuesslein/c3eb4b162561686ad739837e1495be84 to your computer and use it in GitHub Desktop.
a svelte component for Friendly Captcha (https://friendlycaptcha.com/)
<script lang="ts">
import { WidgetInstance } from "friendly-challenge"
import { createEventDispatcher, onDestroy, onMount } from "svelte"
const dispatch = createEventDispatcher<{ solve: string }>()
export let sitekey: string
let widgetDiv: HTMLDivElement
let widget: WidgetInstance
onMount(() => {
widget = new WidgetInstance(widgetDiv, {
doneCallback: (solution: string) => dispatch("solve", solution),
sitekey: sitekey,
})
widget.start()
})
onDestroy(() => {
if (widget) widget.destroy()
})
</script>
<!-- According to the docs https://docs.friendlycaptcha.com/#/widget_api:
"This element should contain the `frc-captcha` class for correct styling
-->
<div class="frc-captcha" bind:this={widgetDiv}></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment