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
| Method | Setup effort | Detection accuracy | UX impact | Framework compatibility | Maintenance |
|---|---|---|---|---|---|
| Behavioral analysis | Low – add a small event logger | High – catches sophisticated bots | Minimal – runs in background | Works with any SPA | Low – update event list occasionally |
| API‑based detection | Medium – inject init script that checks APIs | Very high – spots API tampering | None – runs before UI renders | Requires script in build pipeline | Medium – monitor API changes |
| Page‑load challenges | High – add CAPTCHA library and wait for solve | Variable – can be solved by advanced bots | High – adds friction for real users | Depends on challenge library | High – 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.webdriverflag or overriddenWebGLproperties.
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
- Include BotRefund’s Playwright Init Script (source S1) in the build pipeline. The script runs before any framework code.
- Collect API‑based signals and store them in a global object.
- Instrument the SPA to emit behavioral events (mousemove, scroll, click, keypress) to a lightweight logger.
- When the first meaningful user interaction occurs, send both the API signals and the accumulated behavioral events to BotRefund’s prediction API.
- 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.
- 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
- Add BotRefund’s Playwright Init Scripts to your SPA build (see source).
- Ensure the script runs before any UI framework mounts.
- Collect the API‑based signal and send it to BotRefund’s prediction API.
- Combine the API‑based signal with behavioral events (mouse, scroll) for a final score.
- 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
| Fact | Source |
|---|---|
| 106 independent checks used to build a reliable picture | S1 |
| Signal evaluated by AI yields 99% accuracy | S1 |
| 110+ signals combined for 99% confidence | S2 |
| 83% approval rate for refund claims | S7 |
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.