1
0
forked from icd/rentgen
rentgen/scripts/test_start_extension.sh
Jacek Wielemborek 3df9dfd217 i18n: translate test_start_extension.sh to English
- Translated comments and echo messages
- No functional changes
- Part of comprehensive English translation effort
2025-10-25 20:08:32 +02:00

85 lines
3.2 KiB
Bash

#!/bin/bash
#
# test_start_extension.sh - Starts Rentgen extension in headless Firefox with verification
#
# This script is used by Docker runtime stage to:
# 1. Start Xvfb (virtual X server) on display :99
# 2. Run web-ext with verbose logging
# 3. Verify extension was installed correctly
# 4. Verify extension code executed (by checking ABSENCE of errors)
#
# IMPORTANT: console.error from background pages does NOT appear in web-ext stdout
# (Firefox limitation). Verification works by:
# - Checking that extension installed
# - Checking NO JavaScript errors in logs
# - No errors = code executed correctly
#
set -e
echo "Starting Xvfb on display :99..."
Xvfb :99 -screen 0 1024x768x24 &
XVFB_PID=$!
sleep 2
echo "Xvfb started with PID: $XVFB_PID"
echo "Starting web-ext run with verbose logging..."
echo "========================================"
# Run web-ext with verbose logging and capture output
npx web-ext run --verbose 2>&1 | tee /tmp/web-ext.log &
WEBEXT_PID=$!
# Wait for extension installation confirmation
echo "Waiting for extension to install..."
for i in {1..30}; do
if grep -q "Installed /app as a temporary add-on" /tmp/web-ext.log 2>/dev/null; then
echo "========================================"
echo "✓ SUCCESS: Extension installed!"
echo "✓ Firefox is running in headless mode"
echo "✓ Extension: rentgen@internet-czas-dzialac.pl"
# Give extension time to initialize
sleep 3
# CRITICAL: Check for JavaScript errors
echo ""
echo "Checking for JavaScript errors in extension code..."
# Filter out unrelated Firefox errors (BackupService, RSLoader, etc.)
if grep -i "JavaScript error.*background.js\|SyntaxError.*background\|ReferenceError.*background" /tmp/web-ext.log 2>/dev/null | grep -v "BackupService\|RSLoader"; then
echo ""
echo "========================================"
echo "✗✗✗ CRITICAL ERROR ✗✗✗"
echo "========================================"
echo "Found JavaScript errors in background.js!"
echo "Extension installed but CODE DID NOT EXECUTE!"
echo ""
echo "Errors:"
grep -i "JavaScript error.*background.js\|SyntaxError.*background\|ReferenceError.*background" /tmp/web-ext.log 2>/dev/null | head -10
echo "========================================"
exit 1
else
echo "✓ NO JavaScript errors in background.js"
echo "✓ Extension code executed successfully!"
echo ""
echo "NOTE: console.error from background pages does NOT"
echo " appear in web-ext logs (Firefox limitation)."
echo " Absence of errors = proof of execution."
fi
echo ""
echo "✓ Process info:"
ps aux | grep -E "(firefox|Xvfb)" | grep -v grep | head -3
echo "========================================"
echo "Extension is ready and VERIFIED working."
echo "Press Ctrl+C to stop."
echo "========================================"
break
fi
sleep 1
done
# Keep container running and show logs
wait $WEBEXT_PID