website-htmx-rustelo-code/scripts/wrks/real-browser-logs-collector.sh

120 lines
3.3 KiB
Bash
Raw Normal View History

2026-07-10 03:44:13 +01:00
#!/bin/bash
# Real Browser Logs Collector
# This script integrates with MCP browser tools to collect actual logs
# Usage: ./real-browser-logs-collector.sh [log_file]
set -e
LOG_FILE="$1"
if [ -z "$LOG_FILE" ]; then
LOG_FILE="/tmp/browser_logs_$(date +%Y%m%d_%H%M%S).log"
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE} $1${NC}"; }
log_success() { echo -e "${GREEN}$1${NC}"; }
log_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
log_error() { echo -e "${RED}$1${NC}"; }
# Check if Chrome is running
check_chrome() {
if pgrep -f "Google Chrome" > /dev/null; then
log_success "Chrome is running"
return 0
else
log_error "Chrome is not running"
return 1
fi
}
# Collect real browser logs function
collect_real_logs() {
local temp_log="/tmp/mcp_logs_$(date +%H%M%S).tmp"
log_info "Collecting real browser logs..."
# Create log header
{
echo "========================================"
echo "Real Browser Logs Collection"
echo "Timestamp: $(date)"
echo "========================================"
echo ""
} > "$temp_log"
# Try to collect console logs
log_info "1. Collecting console logs..."
{
echo "=== CONSOLE LOGS ==="
echo "[PLACEHOLDER: Use MCP browser tools to get console logs]"
echo "Command: mcp__browser-tools__getConsoleLogs"
echo ""
} >> "$temp_log"
# Try to collect console errors
log_info "2. Collecting console errors..."
{
echo "=== CONSOLE ERRORS ==="
echo "[PLACEHOLDER: Use MCP browser tools to get console errors]"
echo "Command: mcp__browser-tools__getConsoleErrors"
echo ""
} >> "$temp_log"
# Try to collect network errors
log_info "3. Collecting network errors..."
{
echo "=== NETWORK ERRORS ==="
echo "[PLACEHOLDER: Use MCP browser tools to get network errors]"
echo "Command: mcp__browser-tools__getNetworkErrors"
echo ""
} >> "$temp_log"
# Add completion timestamp
{
echo "========================================"
echo "Log collection completed at: $(date)"
echo "========================================"
} >> "$temp_log"
# Append to main log file
cat "$temp_log" >> "$LOG_FILE"
rm "$temp_log"
log_success "Browser logs collected to: $LOG_FILE"
return 0
}
# Main execution
main() {
log_info "Real Browser Logs Collector"
log_info "Log file: $LOG_FILE"
if ! check_chrome; then
log_warning "Starting Chrome on localhost:3030..."
open -a "Google Chrome" "http://localhost:3030/"
sleep 5
fi
collect_real_logs
echo ""
echo "========================================"
log_success "COLLECTION COMPLETED"
echo "========================================"
log_info "File: $LOG_FILE"
log_warning "Replace placeholders with real MCP browser tool output"
echo ""
echo "To get real logs, run these commands in Claude Code:"
echo " mcp__browser-tools__getConsoleLogs"
echo " mcp__browser-tools__getConsoleErrors"
echo " mcp__browser-tools__getNetworkErrors"
}
main