Skip to content

Instantly share code, notes, and snippets.

@vinhjaxt
Created September 9, 2024 08:52
Show Gist options
  • Save vinhjaxt/cc2043f5425dff5dc860b741d6a7b9da to your computer and use it in GitHub Desktop.
Save vinhjaxt/cc2043f5425dff5dc860b741d6a7b9da to your computer and use it in GitHub Desktop.
Cloudflare Turnstile Captcha
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Captcha</title>
<style>
html,
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="cf-turnstile-el" class="cf-turnstile"></div>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onloadTurnstileCallback"
defer></script>
<script>
const cfTurnStileSiteKey = '0x4AAAAAAAi0u5-vlDWayczz'
window.onloadTurnstileCallback = function () {
// Reset: turnstile.reset(window.turnstileCurrentWidget)
window.turnstileCurrentWidget = turnstile.render('#cf-turnstile-el', {
sitekey: cfTurnStileSiteKey,
callback: function (token) {
console.log(`Captcha Challenge Success:`, token);
if (window.flutter_inappwebview) {
window.flutter_inappwebview.callHandler('GotCaptchaToken', token).then(function (r) {
console.log('Result:', r);
});
} else if (typeof WebviewCaptcha != 'undefined') {
WebviewCaptcha.postMessage(token);
}
},
});
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment