Detecting Javascript Detections 'Complete'

Hi,

I am using ‘Javascript Detections’ on my page and want to initiate a ‘page refresh’ once the detection script is ‘done’.

Is there a way to do this?

I see different ‘load times’ depending on the browser and it can take up to 5 seconds for the detections to complete sometimes…

Maybe there is a variable I can check?

if(CF.detection.complete){
myscript();

Or something similar? Thank you for reading.

Reference: JavaScript detections · Cloudflare bot solutions docs

Hi,

I ended up looking for teh document cookie to complete this. If there is a better way, please let me know!

Also, I ran into a “bug” I think that i spent a few hours on trying to figure out. I still coudln’t figure it out and had to use ?timestamp in my URL to “fix it”.

Here’s what’s happening:

In my “Snippet” I have a rule setup to show

(not http.cookie contains "cf_clearance=" and not http.cookie contains "exptt=")

Inside of my “Snippet”, I am setting a cookie “exptt” and “refreshing” the page.

No matter what I do, there are two problems:

const cookie = request.headers.get("Cookie");

Inside of the ‘Snippet’ returns ‘null’ even when there is a cookie set.

I attempted to override the snippet to no longer display if those cookies are set, yet the ‘snippet’ still shows.

It’s basically showing a ‘cached page’ and if I refresh it doesn’t work no matter what. If I open developer tools and refresh, it does. It’s some type of cache, I tried to manipulate the response headers but I cannot figure it out still because of the HTMLRewriter.

As far as I can see so far, everything responds with ‘nocache’ and I even added a HTML header into the response document.

ANy help would be super awesome. Here’s the “Project”.

https://dash.cloudflare.com/c05d7c895181242fe24a0fbb9bee1193/infinitesweeps.com/rules/snippets/edit/code-vscode/CookieCheck

And I got a simliar “snippet” that does almost the same thing… yet that one works:

https://dash.cloudflare.com/c05d7c895181242fe24a0fbb9bee1193/infinitesweeps.com/rules/snippets/edit/code-vscode/BlockBots

This one has no problem with a ‘location.reload(true);’

I think the difference is that this snippet, has a ‘Turnstile’ and it takes 5 seconds or more before the page is ‘refreshed’

The other one can refresh in as little as 1 second and is causing the ‘bug’.

Having const cookie = request.headers.get(“Cookie”); on both of them, is causing inconsistent results. The first one will always return ‘null’

Please let me know if you can help!!!