Clear Corrupted Queue Script

Quick utility to clear corrupted sync queue and reset local storage

Clear Corrupted Queue Script

🎯 Purpose

This script clears corrupted sync queue data and resets your local storage to start fresh with backend synchronization.


🚀 Quick Fix - Run in Console

Option 1: Clear Everything (Recommended for Fresh Start)

Open your browser's DevTools Console (F12) and run:

// Clear corrupted IndexedDB
const databases = await indexedDB.databases();
for (const db of databases) {
  console.log(`Deleting database: ${db.name}`);
  await indexedDB.deleteDatabase(db.name);
}

// Clear localStorage
localStorage.clear();

// Clear sessionStorage
sessionStorage.clear();

console.log('✅ All local data cleared!');
console.log('🔄 Reloading page...');

// Reload page to start fresh
setTimeout(() => location.reload(), 1000);

Option 2: Clear Only Sync Queue (Preserve Local Data)

// Open IndexedDB connection
const dbRequest = indexedDB.open('gograb-space-storage');

dbRequest.onsuccess = async function(event) {
  const db = event.target.result;
  
  try {
    // Clear sync queue
    const transaction = db.transaction(['storage'], 'readwrite');
    const store = transaction.objectStore('storage');
    
    // Delete sync queue key
    await store.delete('core-angular:sync:queue');
    
    console.log('✅ Sync queue cleared!');
    console.log('🔄 Reloading page...');
    
    setTimeout(() => location.reload(), 1000);
  } catch (error) {
    console.error('Failed to clear sync queue:', error);
  }
};

dbRequest.onerror = function() {
  console.error('Failed to open database');
};

Option 3: Clear Only Spaces (Start with Fresh Backend Data)

// Open IndexedDB connection
const dbRequest = indexedDB.open('gograb-space-storage');

dbRequest.onsuccess = async function(event) {
  const db = event.target.result;
  
  try {
    const transaction = db.transaction(['storage'], 'readwrite');
    const store = transaction.objectStore('storage');
    
    // Get all keys
    const allKeys = await store.getAllKeys();
    
    // Delete all space-related keys
    for (const key of allKeys) {
      if (key.startsWith('space_') || key.startsWith('universe_')) {
        await store.delete(key);
        console.log(`Deleted: ${key}`);
      }
    }
    
    // Also clear sync queue
    await store.delete('core-angular:sync:queue');
    
    console.log('✅ Space data and sync queue cleared!');
    console.log('🔄 Reloading page...');
    
    setTimeout(() => location.reload(), 1000);
  } catch (error) {
    console.error('Failed to clear space data:', error);
  }
};

dbRequest.onerror = function() {
  console.error('Failed to open database');
};

🔍 Verify Cleanup

After running the script and reloading:

  1. Check Console - Should see no "undefined entity" errors
  2. Check Application Storage:
    • DevTools → Application → IndexedDB → gograb-space-storage
    • Should be empty or have only fresh data
  3. Check Network - Should see API calls to /spaces/initialize

⚠️ Important Notes

Which Option Should I Use?

Scenario Recommended Option Reason
First time fixing Option 1 (Clear Everything) Ensures completely clean state
Preserve local changes Option 2 (Queue Only) Keeps local data, clears queue
Fetch fresh from backend Option 3 (Spaces Only) Clears spaces, keeps settings

What Happens After Clearing?

  1. Page reloads automatically
  2. Backend authentication occurs
  3. Space initialization fetches or creates space
  4. Sync begins with clean queue
  5. Data merges intelligently from backend

If You See Errors After Clearing

If you still see issues after clearing:

  1. Hard reload: Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (Mac)
  2. Disable cache: DevTools → Network → Disable cache
  3. Incognito mode: Test in a fresh incognito window
  4. Check backend: Verify backend is running and accessible

🛠️ Troubleshooting

Error: "Failed to open database"

Solution: Database might be locked. Close all tabs with the application and try again.

Error: "Transaction failed"

Solution: Use Option 1 (Clear Everything) instead.

Error: "Cannot read property 'objectStore'"

Solution: The database structure might be different. Use Option 1 (Clear Everything).

No Errors but Still Seeing Issues

Solution:

  1. Clear browser cache completely
  2. Close ALL browser tabs with the application
  3. Reopen in a single tab
  4. Run Option 1 (Clear Everything)

📋 Manual Steps (If Scripts Fail)

If the scripts don't work, you can manually clear data:

  1. Open DevTools (F12)
  2. Go to Application tab
  3. IndexedDB → Right-click gograb-space-storage → Delete database
  4. Local Storage → Right-click → Clear
  5. Session Storage → Right-click → Clear
  6. Reload page (Ctrl+R)

🎯 After Cleanup

Once you've cleared the corrupted data:

  1. ✅ Verify: Console should be clean (no "undefined entity" errors)
  2. ✅ Test: Create a new universe
  3. ✅ Confirm: Check backend has the data (API call should show success)
  4. ✅ Multi-browser: Open in different browser, should see same space

📚 Related Documentation


Last Updated: November 17, 2025
Status: Ready for Use