214 lines
No EOL
6.9 KiB
Bash
Executable file
214 lines
No EOL
6.9 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
# Complete Browser Logger V2 - Creates placeholders for Claude Code to inject real logs
|
||
# This script opens browser pages and creates log files with sections for Claude Code to populate
|
||
|
||
set -e
|
||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||
BASE_URL="http://localhost:3030"
|
||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||
|
||
# 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}"; }
|
||
|
||
# Function to test a page with complete automation
|
||
test_page_complete() {
|
||
local page="$1"
|
||
local log_path="$2"
|
||
local url="${BASE_URL}${page}"
|
||
local page_name=$(echo "$page" | sed 's|/||g' | sed 's|^$|root|')
|
||
|
||
# Determine log file path
|
||
local log_file=""
|
||
if [ -n "$log_path" ]; then
|
||
if [ -d "$log_path" ]; then
|
||
log_file="${log_path}/${page_name}_${TIMESTAMP}.log"
|
||
else
|
||
log_file="$log_path"
|
||
fi
|
||
else
|
||
log_file="/tmp/${page_name}_${TIMESTAMP}.log"
|
||
fi
|
||
|
||
echo ""
|
||
echo "========================================"
|
||
log_info "COMPLETE BROWSER TEST: $page_name"
|
||
log_info "URL: $url"
|
||
log_info "LOG FILE: $log_file"
|
||
echo "========================================"
|
||
|
||
# Initialize log file
|
||
{
|
||
echo "========================================"
|
||
echo "Complete Browser Test Log for: $page_name"
|
||
echo "URL: $url"
|
||
echo "Timestamp: $(date)"
|
||
echo "========================================"
|
||
echo ""
|
||
} > "$log_file"
|
||
|
||
# Check server responds
|
||
if ! curl -s -f "$url" >/dev/null 2>&1; then
|
||
log_error "URL not responding: $url"
|
||
echo "[ERROR] URL not responding: $url" >> "$log_file"
|
||
return 1
|
||
fi
|
||
|
||
# Fresh Chrome session
|
||
log_info "1. Starting fresh Chrome session..."
|
||
echo "[$(date +"%H:%M:%S")] Starting fresh Chrome session..." >> "$log_file"
|
||
osascript -e 'tell application "Google Chrome" to quit' 2>/dev/null || true
|
||
sleep 3
|
||
|
||
# Navigate to page
|
||
log_info "2. Opening Chrome to $url..."
|
||
echo "[$(date +"%H:%M:%S")] Opening Chrome to $url" >> "$log_file"
|
||
open -a "Google Chrome" "$url"
|
||
|
||
# Wait for hydration
|
||
log_info "3. Waiting for complete hydration (12s)..."
|
||
echo "[$(date +"%H:%M:%S")] Waiting for hydration..." >> "$log_file"
|
||
sleep 12
|
||
|
||
log_info "4. Page loaded and hydrated"
|
||
echo "[$(date +"%H:%M:%S")] Page loaded and hydrated" >> "$log_file"
|
||
|
||
# Create signal file for Claude Code
|
||
local signal_file="/tmp/claude_mcp_logs_$(date +%s)_${page_name}.signal"
|
||
{
|
||
echo "CLAUDE_CODE_MCP_REQUEST"
|
||
echo "PAGE=$page"
|
||
echo "URL=$url"
|
||
echo "LOG_FILE=$log_file"
|
||
echo "ACTION=INJECT_REAL_BROWSER_LOGS"
|
||
echo "TIMESTAMP=$(date)"
|
||
} > "$signal_file"
|
||
|
||
# Add placeholder sections for Claude Code to replace
|
||
log_info "5. Creating placeholder sections for Claude Code..."
|
||
echo "[$(date +"%H:%M:%S")] Creating placeholder sections for Claude Code..." >> "$log_file"
|
||
|
||
{
|
||
echo ""
|
||
echo "--- AUTOMATIC BROWSER LOG COLLECTION ---"
|
||
echo ""
|
||
echo "CLAUDE_MCP_INJECT_START"
|
||
echo "# Claude Code: Replace this entire section with real MCP browser logs"
|
||
echo "# Signal file: $signal_file"
|
||
echo "# Commands to run:"
|
||
echo "# mcp__browser-tools__getConsoleLogs"
|
||
echo "# mcp__browser-tools__getConsoleErrors"
|
||
echo "# mcp__browser-tools__getNetworkErrors"
|
||
echo "#"
|
||
echo "# Expected format:"
|
||
echo "# === REAL BROWSER LOGS (Collected [timestamp]) ==="
|
||
echo "# === CONSOLE LOGS ==="
|
||
echo "# [LOG] entry 1"
|
||
echo "# [WARNING] entry 2"
|
||
echo "# === CONSOLE ERRORS ==="
|
||
echo "# [ERROR] error 1"
|
||
echo "# === NETWORK ERRORS ==="
|
||
echo "# (details or 'No network errors detected')"
|
||
echo "CLAUDE_MCP_INJECT_END"
|
||
echo ""
|
||
echo "[$(date +"%H:%M:%S")] Placeholder sections created - ready for Claude Code"
|
||
} >> "$log_file"
|
||
|
||
log_success "Complete test setup finished: $log_file"
|
||
log_info "Signal file created: $signal_file"
|
||
log_warning "Claude Code should now inject real browser logs"
|
||
echo "LOG_FILE_CREATED:$log_file:$signal_file"
|
||
|
||
return 0
|
||
}
|
||
|
||
# Show usage
|
||
show_usage() {
|
||
local script_name=$(basename "$0")
|
||
echo "🔧 Complete Browser Logger V2 - Claude Code MCP Integration"
|
||
echo "Opens browser pages and creates logs with placeholders for Claude Code"
|
||
echo ""
|
||
echo "Usage:"
|
||
echo " $script_name /blog # Test blog page"
|
||
echo " $script_name /blog /path/to/log.log # Test with specific log file"
|
||
echo " $script_name all # Test all pages"
|
||
echo " $script_name all /logs/ # Test all pages in directory"
|
||
echo ""
|
||
echo "Features:"
|
||
echo " ✅ Opens browser automatically"
|
||
echo " ✅ Waits for complete hydration"
|
||
echo " ✅ Creates signal files for Claude Code"
|
||
echo " ✅ Placeholder sections for real MCP logs"
|
||
echo " 🔄 Requires Claude Code to inject real browser data"
|
||
echo ""
|
||
}
|
||
|
||
# Main function
|
||
main() {
|
||
if [ $# -eq 0 ] || [ "$1" = "help" ] || [ "$1" = "-h" ]; then
|
||
show_usage
|
||
exit 0
|
||
fi
|
||
|
||
local pages_to_test=()
|
||
local log_path=""
|
||
|
||
# Parse arguments
|
||
if [ $# -ge 2 ]; then
|
||
log_path="$2"
|
||
fi
|
||
|
||
if [ "$1" = "all" ]; then
|
||
local ALL_PAGES=("/" "/blog" "/prescriptions" "/contact" "/services" "/about")
|
||
pages_to_test=("${ALL_PAGES[@]}")
|
||
log_info "Testing ALL pages with placeholder creation"
|
||
else
|
||
pages_to_test=("$1")
|
||
log_info "Testing page: $1 with placeholder creation"
|
||
fi
|
||
|
||
# Check server health
|
||
if ! curl -s -f "$BASE_URL" >/dev/null 2>&1; then
|
||
log_error "Server not responding at $BASE_URL"
|
||
log_error "Please start server: just dev"
|
||
exit 1
|
||
fi
|
||
|
||
log_success "Server is responding"
|
||
|
||
# Test each page with placeholder creation
|
||
local success_count=0
|
||
local total_count=${#pages_to_test[@]}
|
||
|
||
for page in "${pages_to_test[@]}"; do
|
||
if test_page_complete "$page" "$log_path"; then
|
||
((success_count++))
|
||
fi
|
||
done
|
||
|
||
echo ""
|
||
echo "========================================"
|
||
log_info "PLACEHOLDER CREATION FINISHED"
|
||
echo "========================================"
|
||
log_success "Successfully created placeholders: $success_count/$total_count pages"
|
||
log_warning "Claude Code should now inject real MCP browser logs into the files"
|
||
|
||
if [ "$log_path" ]; then
|
||
log_info "Log files created in: $log_path"
|
||
else
|
||
log_info "Log files created in: /tmp/"
|
||
fi
|
||
}
|
||
|
||
# Run main function
|
||
main "$@" |