tractatus/public/js/sw-reset.js
TheFlow 2a727a80b8 feat: Complete Phase 2 Agent Lightning website integration
- Added Agent Lightning research section to researcher.html with Demo 2 results
- Created comprehensive /integrations/agent-lightning.html page
- Added Agent Lightning link in homepage hero section
- Updated Discord invite links (Tractatus + semantipy) across all pages
- Added feedback.js script to all key pages for live demonstration

Phase 2 of Master Plan complete: Discord setup → Website completion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 14:38:20 +13:00

63 lines
2.2 KiB
JavaScript

/**
* Emergency Service Worker Reset - One-time execution
* Forces complete service worker and cache cleanup
* Fixes stuck service worker showing stale content
*
* This script runs ONCE per browser and then never again.
* It unregisters all service workers, clears all caches, and forces reload.
*/
(async function() {
'use strict';
const RESET_FLAG = 'tractatus_sw_reset_v2_complete';
const RESET_VERSION = '0.1.5'; // Increment this to force another reset if needed
// Check if reset already completed for this version
const completedVersion = localStorage.getItem(RESET_FLAG);
if (completedVersion === RESET_VERSION) {
console.log('[SW Reset] Already completed for version', RESET_VERSION);
return;
}
console.log('[SW Reset] Starting emergency service worker reset...');
try {
// Step 1: Unregister ALL service workers
if ('serviceWorker' in navigator) {
const registrations = await navigator.serviceWorker.getRegistrations();
console.log(`[SW Reset] Found ${registrations.length} service worker(s) to unregister`);
for (const registration of registrations) {
const unregistered = await registration.unregister();
console.log('[SW Reset] Unregistered service worker:', unregistered ? 'success' : 'failed');
}
}
// Step 2: Delete ALL caches
if ('caches' in window) {
const cacheNames = await caches.keys();
console.log(`[SW Reset] Found ${cacheNames.length} cache(s) to delete`);
for (const cacheName of cacheNames) {
const deleted = await caches.delete(cacheName);
console.log(`[SW Reset] Deleted cache "${cacheName}":`, deleted ? 'success' : 'failed');
}
}
// Step 3: Mark reset as complete
localStorage.setItem(RESET_FLAG, RESET_VERSION);
console.log('[SW Reset] Reset complete - reloading page...');
// Step 4: Force reload to start fresh
// Use location.reload(true) to bypass cache (though some browsers ignore the parameter)
setTimeout(() => {
window.location.reload();
}, 500);
} catch (error) {
console.error('[SW Reset] Error during reset:', error);
// Even if reset fails, mark as complete to avoid infinite reload loop
localStorage.setItem(RESET_FLAG, RESET_VERSION);
}
})();