getResponse returning Uncaught TypeError

We are testing Turnstile using the explicit initialization method. We render the widget using the render() method. The Turnstile component is rendering correctly and is showing ‘Success!’, all good so far.

Lets assume the render() method returns a widgetId of: cf-chl-widget-xxxxx

If I run:


… the Turnstile component resets correctly.

However, if I run


I am getting the following error:

Uncaught TypeError: Cannot read properties of undefined (reading ‘response’)
at Object.getResponse (api.js?onload=wsf_turnstile_onload&render=explicit:1:4877)
at :1:11

In your minified api.js script this appears to be associated with:

getResponse(t) { let e = l(t); if (!e) { c(Could not find widget for getResponse(${t})); return } return n.get(e).response }

So n.get(e) does not have ‘response’ defined.

Your documentation states:

In addition to the render() function, Turnstile supports obtaining the widget’s response from a widgetId via the turnstile.getResponse(widgetId: string) function.

I need to be able to check the status of the widget for form validation purposes.

We are getting a 401 error on a pat request but I understand that is expected per another topic I read.

All other requests to Cloudflare are working fine with 200 responses.

e.g. /cdn-cgi/challenge-platform

Am I calling getResponse() correctly or is this an issue with the beta?



This also occurs with your sample explicit code:




It currently expects just the last part of the widget ID due to a bug, but will be fixed to support it with and without the ch-chl-widget prefix.


@KianNH thanks for the update!

Just a followup that if you try getResponse using the ID without the ch-chl-widget- prefix and the ID starts with a number, you get the following error:

api.js?onload=wsf_turnstile_onload&render=explicit:1 Uncaught DOMException: Failed to execute ‘querySelector’ on ‘Document’: ‘23lu2’ is not a valid selector.

Thanks for the report, @mark135, we’ll fix these issues as mentioned in Wrong documentation or implementation error in Turnstile `turnstile.getResponse(widgetId: string)` function · Issue #6070 · cloudflare/cloudflare-docs · GitHub!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.