Platform Interception & Capture
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Platform Interception & Capture is a core subsystem within the SweepBot browser extension designed to passively track user activity across various sweepstakes casino platforms. The system employs XHR and Fetch "monkey-patching" techniques to monitor network traffic in real-time, allowing it to extract critical transaction data such as bets, wins, and balance changes without requiring manual user input.
The primary purpose of this module is to feed the broader SweepBot ecosystem with high-fidelity data for RTP (Return to Player) calculation, volatility analysis, and cross-platform portfolio visibility. By intercepting communication between the casino's frontend and its servers, SweepBot can maintain an accurate, real-time audit trail of all coin movements.
Sources: AGENTS.md, CLAUDE.md, SWEEPBOT_DASHBOARD.html
Architecture and Data Flow
The interception logic resides in the apps/extension workspace, utilizing the WXT (Web Extension Tools) framework. The system operates as a middle layer between the platform's web interface and its backend API.
Capture Pipeline
The data flow follows a specific lifecycle from interception on the casino site to visualization on the user's dashboard:
- Interception: The extension monkey-patches standard web APIs (
XHR/Fetch) on supported casino domains. - Extraction: Specific data points—including
{bet, win, balance}—are extracted from the intercepted responses. - Batching: To optimize performance and reduce network overhead, transactions are batched before being sent to the backend.
- Persistence: The backend API processes the batch via a dedicated endpoint (
POST /transactions/batch). - Analytics: The data is persisted to PostgreSQL, where RTP and other metrics are calculated for the web dashboard.
The diagram above illustrates how the extension intercepts site traffic to feed the centralized analytics engine.
Sources: CLAUDE.md, SWEEPBOT_DASHBOARD.html
Key Components
Transaction Interceptor
The interceptor.ts library is responsible for the low-level implementation of network monitoring. It targets specific API calls characteristic of sweepstakes platforms to identify coin movements.
| Feature | Description |
|---|---|
| XHR Hooking | Overrides XMLHttpRequest.prototype.open and send to inspect request/response cycles. |
| Fetch Hooking | Proxies the global window.fetch to capture data from modern web applications. |
| Data Extraction | Identifies specific fields like bet_amount, win_amount, and current_balance. |
| Platform Detection | Uses platforms.ts to apply correct extraction logic based on the current domain. |
Platform-Specific Capture
The platform-capture.ts module (alongside platforms.ts) contains the logic required to handle the unique API structures of various casinos. The system currently supports over 10 platforms.
Real-time RTP Calculator
Calculated values from captured transactions are processed by the rtp-calculator.ts library. This component provides:
- Real-time RTP updates.
- Volatility calculation based on win/loss variance.
- Confidence intervals for the statistical significance of the data.
Sources: AGENTS.md, SWEEPBOT_DASHBOARD.html
Implementation Details
Batch Transaction Endpoint
To ensure the high-frequency nature of casino games does not overwhelm the API, the capture system utilizes a specialized "hot-path" endpoint.
- Endpoint:
POST /sessions/transactions/batch - Capacity: Supports up to 500 transactions in a single HTTP call.
- Logic: Performs a single
UPDATEfor session totals while performing a bulkINSERTfor individual transactions, maintaining $O(1)$ efficiency for session updates.
Sources: SWEEPBOT_DASHBOARD.html
Device Information Capture
The capture system is designed to collect metadata about the environment where the transactions occur. This is stored in a JSONB column named device_info within the sessions table.
{
"browser": "Chrome",
"browserVersion": "122.0.0",
"os": "Windows",
"osVersion": "11",
"deviceType": "desktop",
"screenRes": "1920x1080",
"timezone": "America/New_York",
"language": "en-US"
}
Sources: SWEEPBOT_DASHBOARD.html, QUICK_WINS_CHECKLIST.md
Conclusion
The Platform Interception & Capture module is the primary data ingestion point for SweepBot. By leveraging non-intrusive monitoring of platform APIs, it enables sophisticated features like the Trust Index and Redemption Benchmarks. The architecture is optimized for performance through batching and relies on a type-safe implementation across the WXT extension and Fastify API.
Sources: AGENTS.md, CLAUDE.md, SWEEPBOT_DASHBOARD.html