/** * Safari Reload Loop Prevention System * Prevents infinite reload loops that can occur in Safari when page crashes * * @package HVAC_Community_Events * @since 2.0.0 */ (function() { 'use strict'; class SafariReloadPrevention { constructor() { this.threshold = 3; this.timeWindow = 10000; // 10 seconds this.storageKey = 'hvac_safari_reloads'; this.checkReloadLoop(); } checkReloadLoop() { try { const data = JSON.parse(sessionStorage.getItem(this.storageKey) || '{"reloads":[]}'); const now = Date.now(); // Clean old entries outside time window data.reloads = data.reloads.filter(time => now - time < this.timeWindow); // Add current reload timestamp data.reloads.push(now); // Check if we've exceeded reload threshold if (data.reloads.length >= this.threshold) { this.handleLoop(); return; } // Save updated reload data sessionStorage.setItem(this.storageKey, JSON.stringify(data)); console.log('[Safari Reload Prevention] Reload tracked:', data.reloads.length, 'of', this.threshold); } catch (error) { console.error('[Safari Reload Prevention] Error checking reload loop:', error); } } handleLoop() { console.error('[Safari Reload Prevention] Reload loop detected! Stopping page execution.'); // Clear the reload tracking try { sessionStorage.removeItem(this.storageKey); } catch (e) { // Silent fail if storage not available } // Stop any further page loading if (window.stop) { window.stop(); } // Replace page content with user-friendly error message document.documentElement.innerHTML = ` Page Loading Issue
⚠️

Page Loading Issue Detected

We've detected an issue loading this page in Safari. This can happen due to browser compatibility issues.

Please try one of the following:

Return to Homepage
`; } // Public method to manually reset reload tracking reset() { try { sessionStorage.removeItem(this.storageKey); console.log('[Safari Reload Prevention] Reload tracking reset'); } catch (error) { console.error('[Safari Reload Prevention] Error resetting:', error); } } } // Initialize only on Safari browsers if (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1 && navigator.userAgent.indexOf('Chromium') === -1) { // Run immediately to catch reload loops early window.hvacSafariReloadPrevention = new SafariReloadPrevention(); console.log('[Safari Reload Prevention] System activated'); } })();