# ๐Ÿ” Diagnostics & Error Capture
**๐Ÿ› ๏ธ Automatic error screenshots and HTML snapshots** *Debug smarter with visual evidence*
--- ## ๐ŸŽฏ What is Diagnostics? The diagnostics system **automatically captures** error screenshots and HTML snapshots when issues occur during script execution, providing visual evidence for troubleshooting. ### **Key Features** - ๐Ÿ“ธ **Auto-screenshot** โ€” Visual error capture - ๐Ÿ“„ **HTML snapshots** โ€” Complete page source - ๐Ÿšฆ **Rate limiting** โ€” Prevents storage bloat - ๐Ÿ—‚๏ธ **Auto-cleanup** โ€” Configurable retention - ๐Ÿ”’ **Privacy-safe** โ€” Local storage only --- ## โš™๏ธ Configuration ### **Basic Setup** Add to `src/config.json`: ```json { "diagnostics": { "enabled": true, "saveScreenshot": true, "saveHtml": true, "maxPerRun": 2, "retentionDays": 7 } } ``` ### **Configuration Options** | Setting | Default | Description | |---------|---------|-------------| | `enabled` | `true` | Master toggle for diagnostics capture | | `saveScreenshot` | `true` | Capture PNG screenshots on errors | | `saveHtml` | `true` | Save page HTML content on errors | | `maxPerRun` | `2` | Maximum captures per script run | | `retentionDays` | `7` | Auto-delete reports older than N days | --- ## ๐Ÿš€ How It Works ### **Automatic Triggers** The system captures when these errors occur: - โฑ๏ธ **Page navigation timeouts** - ๐ŸŽฏ **Element selector failures** - ๐Ÿ” **Authentication errors** - ๐ŸŒ **Network request failures** - โšก **JavaScript execution errors** ### **Capture Process** 1. **Error Detection** โ€” Script encounters unhandled error 2. **Visual Capture** โ€” Screenshot + HTML snapshot 3. **Safe Storage** โ€” Local `reports/` folder 4. **Continue Execution** โ€” No blocking or interruption --- ## ๐Ÿ“ File Structure ### **Storage Organization** ``` reports/ โ”œโ”€โ”€ 2025-01-20/ โ”‚ โ”œโ”€โ”€ error_abc123_001.png โ”‚ โ”œโ”€โ”€ error_abc123_001.html โ”‚ โ”œโ”€โ”€ error_def456_002.png โ”‚ โ””โ”€โ”€ error_def456_002.html โ””โ”€โ”€ 2025-01-21/ โ””โ”€โ”€ ... ``` ### **File Naming Convention** ``` error_[runId]_[sequence].[ext] ``` - **RunId** โ€” Unique identifier for each script execution - **Sequence** โ€” Incremental counter (001, 002, etc.) - **Extension** โ€” `.png` for screenshots, `.html` for source --- ## ๐Ÿงน Retention Management ### **Automatic Cleanup** - Runs after each script completion - Deletes entire date folders older than `retentionDays` - Prevents unlimited disk usage growth ### **Manual Cleanup** ```powershell # Remove all diagnostic reports Remove-Item -Recurse -Force reports/ # Remove reports older than 3 days Get-ChildItem reports/ | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-3)} | Remove-Item -Recurse -Force ``` --- ## ๐Ÿ“Š Use Cases | Scenario | Benefit | |----------|---------| | **๐Ÿ› Development & Debugging** | Visual confirmation of page state during errors | | **๐Ÿ” Element Detection Issues** | HTML source analysis for selector problems | | **๐Ÿ“ˆ Production Monitoring** | Evidence collection for account issues | | **โšก Performance Analysis** | Timeline reconstruction of automation failures | --- ## โšก Performance Impact ### **Resource Usage** - **Screenshots** โ€” ~100-500KB each - **HTML files** โ€” ~50-200KB each - **CPU overhead** โ€” Minimal (only during errors) - **Memory impact** โ€” Asynchronous, non-blocking ### **Storage Optimization** - Daily cleanup prevents accumulation - Rate limiting via `maxPerRun` - Configurable retention period --- ## ๐ŸŽ›๏ธ Environment Settings ### **Development Mode** ```json { "diagnostics": { "enabled": true, "maxPerRun": 5, "retentionDays": 14 } } ``` ### **Production Mode** ```json { "diagnostics": { "enabled": true, "maxPerRun": 2, "retentionDays": 3 } } ``` ### **Debug Verbose Logging** ```powershell $env:DEBUG_REWARDS_VERBOSE=1; npm start ``` --- ## ๐Ÿ› ๏ธ Troubleshooting | Problem | Solution | |---------|----------| | **No captures despite errors** | Check `enabled: true`; verify `reports/` write permissions | | **Excessive storage usage** | Reduce `maxPerRun`; decrease `retentionDays` | | **Missing screenshots** | Verify browser screenshot API; check memory availability | | **Cleanup not working** | Ensure script completes successfully for auto-cleanup | ### **Common Capture Locations** - **Login issues** โ€” Authentication page screenshots - **Activity failures** โ€” Element detection errors - **Network problems** โ€” Timeout and connection errors - **Navigation issues** โ€” Page load failures --- ## ๐Ÿ”— Integration ### **With Notifications** Diagnostics complement [Discord Webhooks](./conclusionwebhook.md) and [NTFY](./ntfy.md): - **Webhooks** โ€” Immediate error alerts - **Diagnostics** โ€” Visual evidence for investigation - **Combined** โ€” Complete error visibility ### **With Development Workflow** ```bash # 1. Run script with diagnostics npm start # 2. Check for captures after errors ls reports/$(date +%Y-%m-%d)/ # 3. Analyze screenshots and HTML # Open .png files for visual state # Review .html files for DOM structure ``` --- ## ๐Ÿ”’ Privacy & Security - **Local Only** โ€” All captures stored locally - **No Uploads** โ€” Zero external data transmission - **Account Info** โ€” May contain sensitive data - **Secure Storage** โ€” Use appropriate folder permissions - **Regular Cleanup** โ€” Recommended for sensitive environments --- ## ๐Ÿ”— Related Guides - **[Getting Started](./getting-started.md)** โ€” Initial setup and configuration - **[Discord Webhooks](./conclusionwebhook.md)** โ€” Error notification alerts - **[NTFY Notifications](./ntfy.md)** โ€” Mobile push notifications - **[Security](./security.md)** โ€” Privacy and data protection