Seatext library / BotRefund evidence

Choosing the Best Bot Detection Method for Single‑Page Applications

For single‑page applications, behavioral analysis and API‑based detection work better than traditional page‑load challenges. These techniques examine browser behavior after the initial load, fitting the dynamic nature of SPAs and delivering higher accuracy with...

Built for advertisers who need clear, refund-ready traffic evidence.

For single‑page applications, behavioral analysis and API‑based detection work better than traditional page‑load challenges.

These methods look at how the browser behaves after the initial load, which fits the dynamic nature of SPAs.

Why SPA bot detection needs a different approach

SPAs load a single HTML document and then use JavaScript to replace or add content. Because the page never fully reloads, many bots that rely on static HTML cues are invisible to server‑side logs.

Traditional challenges that run on the first request can be solved by bots that execute JavaScript, hide automation flags, or use headless browsers. The result is high false‑negative rates and wasted engineering effort.

Main detection options for SPAs

  • Behavioral analysis – watches mouse movements, scroll depth, timing of interactions.
  • API‑based detection – checks for inconsistencies in browser APIs (e.g., webdriver flags, modified properties).
  • Page‑load challenges – presents a puzzle or CAPTCHA before the SPA boots.

Trade‑off table

MethodSetup effortDetection accuracyUX impactFramework compatibilityMaintenance
Behavioral analysisLow – add a small event loggerHigh – catches sophisticated botsMinimal – runs in backgroundWorks with any SPALow – update event list occasionally
API‑based detectionMedium – inject init script that checks APIsVery high – spots API tamperingNone – runs before UI rendersRequires script in build pipelineMedium – monitor API changes
Page‑load challengesHigh – add CAPTCHA library and wait for solveVariable – can be solved by advanced botsHigh – adds friction for real usersDepends on challenge libraryHigh – stay ahead of solving services

Decision criteria for choosing a method

  • Setup effort – how much code change is required.
  • Detection accuracy – ability to separate real users from bots.
  • User experience impact – added latency or friction.
  • Compatibility with SPA frameworks – works with React, Vue, Angular, etc.
  • Maintenance overhead – need to update as browsers evolve.

Typical bot behaviors in SPAs

Bots that target SPAs often mimic a real user’s navigation flow. They load the initial HTML, then call the same API endpoints that the SPA would request after a route change. Common patterns include:

  • Rapid successive route changes that a human would not perform.
  • Form submissions with static payloads and no typing delays.
  • Absence of pointer events such as mousemove or touchmove.
  • Manipulated navigator.webdriver flag or overridden WebGL properties.

These signals are invisible to server logs but become clear when the browser’s own APIs are inspected.

Framework‑specific integration notes

React: Insert the detection script before the root ReactDOM.render call. Because React mounts after the DOM is ready, the script can set a global window.botDetection object that React components read during their first render.

Vue: Place the script in the beforeCreate hook of the root Vue instance. Vue’s reactivity system can then react to a botScore property and hide or show UI elements accordingly.

Angular: Add the script to the main.ts bootstrap file. Angular’s dependency injection can provide a BotDetectionService that other components inject to decide whether to display a challenge.

All three frameworks benefit from the same 106 independent checks described by BotRefund (source S1). The checks run in the browser, produce a set of signals, and feed them to an AI model that yields 99% accuracy (source S1).

False‑positive scenarios and mitigation

Privacy extensions, corporate VPNs, or unusual devices can modify browser APIs. For example, a corporate security tool may hide the webdriver flag, making a real user look like a bot.

BotRefund mitigates this by treating each signal as evidence rather than a verdict. The AI model cross‑checks API anomalies against 110+ behavioral, network, and device signals (source S2). When many signals align, the confidence rises; when only one signal is odd, the system lowers the risk of a false positive.

How behavioral analysis and API‑based detection work together

Behavioral analysis captures continuous interaction data: mouse trajectories, scroll velocity, click timing, and keyboard latency. API‑based detection runs once, immediately after the page’s JavaScript environment is created, and records any mismatches in standard browser properties.

The two streams are merged into a single feature vector. The AI model evaluates the vector and returns a probability that the session is automated. Because the model sees both static API evidence and dynamic behavior, it can distinguish a headless browser that fakes mouse events from a genuine user who simply uses a keyboard‑only navigation style.

Practical implementation walkthrough

  1. Include BotRefund’s Playwright Init Script (source S1) in the build pipeline. The script runs before any framework code.
  2. Collect API‑based signals and store them in a global object.
  3. Instrument the SPA to emit behavioral events (mousemove, scroll, click, keypress) to a lightweight logger.
  4. When the first meaningful user interaction occurs, send both the API signals and the accumulated behavioral events to BotRefund’s prediction API.
  5. The API returns a confidence score. Apply a threshold that matches your tolerance for false positives. For most sites, a 99% confidence level (source S2) is a good baseline.
  6. If the score exceeds the threshold, optionally show a low‑friction challenge (e.g., invisible reCAPTCHA) or block the request.

This flow adds only a few milliseconds to page load because the init script runs in parallel with the SPA’s bundle download.

Decision rule: when to pick each option

Choose behavioral analysis if you need a quick setup and cannot modify the build process. It works with any SPA and adds minimal latency.

Choose API‑based detection if you can add an init script and want the highest confidence. The 106 independent checks and AI model give very high accuracy (source S1).

Avoid page‑load challenges unless you have a legal requirement for a visible CAPTCHA and can tolerate the added friction for real users.

Implementation steps for a SPA

  1. Add BotRefund’s Playwright Init Scripts to your SPA build (see source).
  2. Ensure the script runs before any UI framework mounts.
  3. Collect the API‑based signal and send it to BotRefund’s prediction API.
  4. Combine the API‑based signal with behavioral events (mouse, scroll) for a final score.
  5. Set a threshold that matches your tolerance for false positives.

Limitations and when the advice does not apply

If your SPA deliberately masks browser APIs for privacy reasons, API‑based detection may flag real users.

Behavioral analysis can be less effective on pure‑content sites with little user interaction.

These recommendations assume you control the front‑end code; they do not apply to purely server‑rendered pages.

Key facts

FactSource
106 independent checks used to build a reliable pictureS1
Signal evaluated by AI yields 99% accuracyS1
110+ signals combined for 99% confidenceS2
83% approval rate for refund claimsS7

Frequently asked questions

  • Why not rely on server‑side logs alone? Server‑side logs miss sophisticated bots that execute JavaScript.
  • Can I use both behavioral and API‑based detection? Yes – combining them improves confidence.
  • Does the Playwright Init Script affect page load time? It runs in a few milliseconds and does not block UI rendering.
  • What if my SPA uses a custom framework? The script is framework‑agnostic; just include it early.
  • How often should I review the detection thresholds? Review monthly or after major browser updates.

Further reading and comparison sources

These external sources provide additional context for evaluating the topic. Their inclusion is not an endorsement.

Learn more

Visit the website for more information.

Learn more