# How invisible JavaScript challenges work

> An invisible JavaScript challenge sends a small script to the browser, which collects details about the browser and device and sometimes solves a proof of work. The results go back to the server, which compares them with network signals it already holds. If they agree, the visitor gets a signed cookie or token and passes without a puzzle. If not, a harder check or a block follows.

Category: CAPTCHA and challenges. Level: Advanced. Updated: 2026-11-24.
Canonical page: https://stopbots.io/learn/captcha/javascript-challenges-explained/

The "checking your browser" page in front of a website and the invisible widget on a login form run the same kind of test. Neither asks the visitor to do anything. They run code in the browser, send the results to a server and get a pass or fail back.

## What does a bot check page do?

1. A request arrives at the edge (CDN or reverse proxy) without a valid clearance cookie, and a rule says it needs a check.
2. The edge returns a small HTML page with the challenge script instead of the content.
3. The script collects signals, sometimes solves a proof of work, and posts the results with a one-time challenge ID.
4. The server scores the results together with what it already knows about the connection.
5. On a pass, it sets a signed clearance cookie and redirects to the original URL. On a doubtful result, it can show an interactive check. On a clear fail, it blocks.
6. Later requests carry the cookie and skip the check until it expires.

Widgets such as Turnstile follow the same steps inside a form and hand back a token instead of setting a cookie on the whole site.

## What does an invisible challenge collect?

Vendors keep their exact checks private and change them often, but the categories are well known:

- Whether JavaScript runs at all, and how long the script takes.
- Whether the browser's claims agree with each other: the User-Agent string, User-Agent client hints, the platform and the features that browser version should support.
- Automation flags. The [WebDriver specification](https://www.w3.org/TR/webdriver/) requires browsers under automation control to report a `webdriver` property set to true.
- Rendering. The WebGL renderer name and canvas output. Software renderers such as SwiftShader or llvmpipe are common on servers without a GPU and rare on consumer devices.
- Device facts: CPU cores, screen and window sizes, time zone and languages, checked against each other and against the IP address's location.
- Interaction, where there is any: pointer movement, focus changes and key timing.

A minimal collector looks like this:

```js
function collectSignals() {
  const gl = document.createElement("canvas").getContext("webgl");
  const debug = gl && gl.getExtension("WEBGL_debug_renderer_info");
  return {
    webdriver: navigator.webdriver === true,
    userAgent: navigator.userAgent,
    platform: navigator.userAgentData?.platform ?? navigator.platform,
    languages: navigator.languages,
    cores: navigator.hardwareConcurrency,
    screen: [screen.width, screen.height, window.outerWidth, window.outerHeight],
    renderer: debug ? gl.getParameter(debug.UNMASKED_RENDERER_WEBGL) : null,
    timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
  };
}
```

The server adds what the browser cannot report about itself: the TLS fingerprint of the connection (see [JA3 and JA4](https://stopbots.io/learn/detection/tls-fingerprinting-ja3-ja4.md)), HTTP/2 settings, header order and the IP address's ASN and reputation. A Chrome User-Agent on a TLS handshake that Chrome never produces is a stronger signal than any single browser property. [Headless browser detection](https://stopbots.io/learn/detection/headless-browser-detection.md) and [browser fingerprinting](https://stopbots.io/learn/detection/what-is-browser-fingerprinting.md) cover these signals in depth.

## Why does the server have to make the decision?

A client that controls its browser can return any values it likes. So the script reports raw values and the server decides:

- Issue a fresh challenge ID for each attempt, sign it, and accept each one only once.
- Reject results that come back implausibly fast, or from a different IP address than the one that received the challenge. Cloudflare's documentation, for example, says a managed challenge solved from a different IP address is not valid.
- Compare the browser's claims with the network layer, because the network layer is harder to fake.
- Change the script regularly, so a bot that copied last month's answers fails.

## What does a visitor get after passing?

Usually a signed cookie scoped to the site:

```http
HTTP/1.1 302 Found
Location: /products/123
Set-Cookie: bot_clearance=v1.1764003600.k3f9a1c0; Path=/; Max-Age=1800; Secure; HttpOnly; SameSite=Lax
```

Sign the value with a server key (an HMAC or a signed JWT), include an expiry, and bind it to something about the client, such as a hash of the TLS fingerprint and User-Agent, so a copied cookie fails on another machine. Thirty minutes is a starting point for content pages. Cloudflare's `cf_clearance` cookie lasts for the Challenge Passage time the site owner sets, and Anubis issues a signed JWT cookie after its proof of work. A clearance cookie should lower the bar for browsing. On login, password reset and checkout, check the request again anyway.

## What happens when JavaScript is disabled?

The challenge cannot run, so the visitor stays on the interstitial or gets an error. Most real visitors have JavaScript on, screen reader users included. Those without it are mostly using hardened privacy setups, text browsers or locked-down corporate machines. Give them a way forward:

```html
<noscript>
  <p>This check needs JavaScript. Turn it on for this site, or email support@example.com if you cannot.</p>
</noscript>
```

Keep low-risk pages, such as help and legal pages, outside the challenge. Let verified search engine crawlers through by confirming their IP addresses, without asking them to run the script (see [how to verify Googlebot and other good bots](https://stopbots.io/learn/scraping/how-to-verify-good-bots.md)).

## How do API clients and fetch requests handle challenges?

A challenge page is HTML, so a `fetch` call that expects JSON breaks. Cloudflare marks challenge responses with a `cf-mitigated: challenge` header, which front-end code can check:

```js
async function loadCart() {
  const res = await fetch("/api/cart", { credentials: "same-origin" });
  if (res.headers.get("cf-mitigated") === "challenge") {
    showMessage("Please reload the page to continue.");
    return null;
  }
  return res.json();
}
```

Then set up the routes so this rarely happens:

- Do not put interstitial challenges on API routes. Authenticate API clients with keys or OAuth, sign requests and set quotas. See [how to protect APIs from bots](https://stopbots.io/learn/implementation/how-to-protect-apis-from-bots.md).
- In single-page apps, get the clearance when the page loads, so later API calls carry the cookie. Cloudflare offers Turnstile pre-clearance for this.
- Mobile apps have no browser to run the script. Use Apple App Attest or Google Play Integrity instead.
- Never challenge webhooks or partner integrations. Allow them by signature or IP range.

## How should you handle challenge failures?

- Decide per endpoint what happens when the challenge service times out. Content pages can fail open and let the request through. Payment and password reset can fail closed or fall back to a step-up check.
- Cap retries. A page that reloads after every failed attempt can loop forever on a browser that will never pass. After two or three failures in a session, show a static page with another way to continue.
- Log every outcome (shown, passed, failed, timed out, error code) by browser and device, and watch the pass rate. Cloudflare reports a [challenge solve rate](https://developers.cloudflare.com/cloudflare-challenges/reference/challenge-solve-rate/) for this.
- Allow the challenge in your Content Security Policy. Add `'wasm-unsafe-eval'` only if your vendor's script uses WebAssembly and its documentation says so:

```http
Content-Security-Policy: script-src 'self' https://challenge.vendor.example 'wasm-unsafe-eval'; frame-src https://challenge.vendor.example
```

- Expect some setups to fail: in-app browsers inside social apps, extensions that change the User-Agent or canvas and WebGL output, blocked cookies, and IP changes between solving and the next request on mobile networks or VPNs.
- Count real customers who fail as [false positives](https://stopbots.io/learn/detection/bot-detection-false-positives.md) and tune the rules that caught them.

## Tools that help

_StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking._
- [Cloudflare Turnstile](https://www.cloudflare.com/application-services/products/turnstile/) and [Cloudflare challenges](https://developers.cloudflare.com/cloudflare-challenges/): managed and non-interactive challenge pages at the edge, and a free widget for forms on any site.
- [Anubis](https://github.com/TecharoHQ/anubis): an open source reverse proxy that issues a proof-of-work challenge and a signed cookie, free for self-hosted sites.
- [Friendly Captcha](https://friendlycaptcha.com/): a hosted puzzle-free widget combining proof of work with risk signals.
- [Kairal](https://www.kairal.io/product/bot-protection/): invisible challenges backed by device, network and behaviour signals, deployed at the CDN, reverse proxy or API, with a preview mode before enforcement and fail-open handling when an evaluation times out.

## Common questions

### What is a bot check?

It is the 'checking your browser' or 'verify you are human' step some sites run before showing a page. It usually finishes on its own in a few seconds and sets a cookie, so the next pages load without the check.

### Why do I keep getting 'verify you are human' loops?

A loop usually means the clearance cookie is not stored or not accepted: cookies are blocked, an extension changes browser properties, or the IP address changed between solving the check and the next request. Allowing cookies for the site, turning off extensions there or trying another browser usually fixes it.

### Can a bot pass a JavaScript challenge?

Yes. A real browser driven by automation runs the script like any other browser. The challenge then depends on how well the collected details expose automation and how the server combines them with network and behaviour signals, which is why vendors change their scripts often.

## Related

- [How to detect headless Chrome and automated browsers](https://stopbots.io/learn/detection/headless-browser-detection.md)
- [CAPTCHA alternatives: how to stop bots without a puzzle](https://stopbots.io/learn/captcha/captcha-alternatives.md)
- [Proof-of-work challenges: how Anubis-style bot checks work](https://stopbots.io/learn/captcha/proof-of-work-challenges.md)
- [How to protect APIs from bots](https://stopbots.io/learn/implementation/how-to-protect-apis-from-bots.md)
