ElliotSowersby / simple-cloudflare-turnstile

WordPress Plugin: Easily add Cloudflare Turnstile to all your WordPress website forms to protect them from spam!
38 stars 12 forks source link

Doesn't always correctly load and verify after reload - plugin appears to be trying to use Turnstile in both explicit and implicit modes #8

Open Standard8 opened 1 year ago

Standard8 commented 1 year ago

We've been attempting to use this plugin on a site that we're developing. One of issues we've been seeing is that quite frequently after a page reload, the "Verifying" stage will hang and the content process of Firefox will be using 100% CPU and ever increasing amounts of memory.

On the console we're seeing messages such as:

[Cloudflare Turnstile] Unable to find onload callback 'onloadTurnstileCallback' after 1 second, expected 'function', got 'undefined'.

Looking at the code, the rendering function in php seems to be using implicit rendering, as it is defining a div with class cf-turnstile.

However, when loading the script an onload function is passed which Cloudflare says will disable implicit rendering and use explicit rendering.

Although it is working to some degree, I think the mixture of implicit and explicit set-up is confusing the turnstile code and causing it to get into the broken state.

ubeyou commented 1 year ago

api.js?onload=onloadTurnstileCallback:1 [Cloudflare Turnstile] Unable to find onload callback 'onloadTurnstileCallback' immediately after loading, expected 'function', got 'undefined'. g @ api.js?onload=onloadTurnstileCallback:1 (anonymous) @ api.js?onload=onloadTurnstileCallback:1 setTimeout (async) (anonymous) @ api.js?onload=onloadTurnstileCallback:1 (anonymous) @ api.js?onload=onloadTurnstileCallback:1

I'm getting the same problem on my woocommerce site too. without ads block

Standard8 commented 1 year ago

I forgot to follow-up on this, I think the performance issue isn't to do with this plugin as it can be reproduced in different ways. I filed that here: https://community.cloudflare.com/t/turnstile-causing-100-cpu-and-memory-increase-when-reloading-pages/509196/5

However, the misconfiguration in this plugin appears to be making the performance issue occur more frequently.

ElliotSowersby commented 1 year ago

Hi,

Thanks for the info, I'll take a look into this.

If you remove ?onload=onloadTurnstileCallback from your code does it resolve your error/issue?

The plugin should only try to explicitly load Turnstile if it failed to implicitly load (it can not find the widget). This helps with some conflicts.