#!/bin/bash # Smart Browser Logger - Works automatically with current Claude Code session # Creates a signal file that Claude Code can detect and process automatically set -e LOG_FILE="$1" PAGE_NAME="$2" URL="$3" if [ $# -lt 3 ]; then echo "Usage: $0 " exit 1 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}"; } # Create signal file for Claude Code to detect SIGNAL_FILE="/tmp/claude_browser_logs_signal_$(date +%s).txt" TIMESTAMP=$(date +"%H:%M:%S") log_info "Smart Browser Logger - Claude Code Integration" log_info "Creating signal for Claude Code session..." # Create the signal file with all necessary information cat > "$SIGNAL_FILE" << EOF CLAUDE_CODE_BROWSER_LOGS_REQUEST LOG_FILE=$LOG_FILE PAGE_NAME=$PAGE_NAME URL=$URL TIMESTAMP=$TIMESTAMP ACTION=COLLECT_AND_INJECT_BROWSER_LOGS STATUS=WAITING_FOR_CLAUDE EOF # Add initial section to log file { echo "" echo "--- SMART BROWSER LOGS (Claude Code Integration) ---" echo "[$TIMESTAMP] Signal created: $SIGNAL_FILE" echo "[$TIMESTAMP] Waiting for Claude Code to detect and process..." echo "" echo "CLAUDE_AUTO_INJECT_START" echo "# Claude Code: Please replace this section with real browser logs" echo "# Run these MCP commands and replace this entire section:" echo "# mcp__browser-tools__getConsoleLogs" echo "# mcp__browser-tools__getConsoleErrors" echo "# mcp__browser-tools__getNetworkErrors" echo "CLAUDE_AUTO_INJECT_END" echo "" echo "[$TIMESTAMP] Smart browser logger signal sent" } >> "$LOG_FILE" log_success "Signal file created: $SIGNAL_FILE" log_warning "Claude Code should automatically detect and process this request" log_info "Log file: $LOG_FILE" # Output the signal file path so Claude Code can find it echo "SIGNAL_CREATED:$SIGNAL_FILE:$LOG_FILE"