-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-realtime.js
More file actions
149 lines (129 loc) · 5.15 KB
/
Copy pathverify-realtime.js
File metadata and controls
149 lines (129 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Realtime Listener Verification Script
// Run this in the browser console to verify Firebase listeners are working
// made by @m4scarade
(async function verifyRealtimeImplementation() {
console.log('🔍 Verifying Firebase Realtime Implementation');
console.log('==============================================\n');
const results = {
passed: 0,
failed: 0,
warnings: 0,
tests: []
};
function test(name, condition, details = '') {
const result = {
name,
passed: condition,
details
};
results.tests.push(result);
if (condition) {
results.passed++;
console.log(`✅ ${name}`);
if (details) console.log(` ${details}`);
} else {
results.failed++;
console.log(`❌ ${name}`);
if (details) console.log(` ${details}`);
}
}
function warn(name, details = '') {
results.warnings++;
console.log(`⚠️ ${name}`);
if (details) console.log(` ${details}`);
}
// Test 1: Check if Firebase is loaded
const firebaseLoaded = typeof firebase !== 'undefined';
test(
'Firebase SDK Loaded',
firebaseLoaded,
firebaseLoaded ? 'Firebase v' + (firebase.SDK_VERSION || 'unknown') : 'Firebase SDK not found'
);
// Test 2: Check if Firebase is initialized
const firebaseInitialized = typeof isFirebaseInitialized === 'function' ? isFirebaseInitialized() : false;
test(
'Firebase Initialized',
firebaseInitialized,
firebaseInitialized ? 'Firebase app is ready' : 'Call initializeFirebase() first'
);
// Test 3: Check if ListenerManager class exists
const listenerManagerExists = typeof FirebaseListenerManager === 'function';
test(
'ListenerManager Class Available',
listenerManagerExists,
listenerManagerExists ? 'FirebaseListenerManager class loaded' : 'firebase-listener-manager.js not loaded'
);
// Test 4: Check config
const config = window.ENHANCED_CONFIG || {};
const listenersEnabled = config.firebaseListeners?.enabled ?? false;
test(
'Realtime Listeners Enabled in Config',
listenersEnabled,
listenersEnabled ? 'config.firebaseListeners.enabled = true' : 'config.firebaseListeners.enabled = false (using polling)'
);
// Test 5: Check if listener manager instance exists (service worker)
if (typeof chrome !== 'undefined' && chrome.storage) {
try {
const state = await chrome.storage.local.get(['listenerManagerState']);
const hasState = !!state.listenerManagerState;
test(
'Listener Manager State Saved',
hasState,
hasState ? `Last update: ${state.listenerManagerState.lastUpdate}` : 'No state found'
);
if (hasState) {
console.log(` Active listeners: ${state.listenerManagerState.activeListeners.join(', ')}`);
}
} catch (e) {
warn('Could not check listener state', e.message);
}
}
// Test 6: Check admin sync client
if (typeof window !== 'undefined' && window.adminSyncClient) {
const syncStatus = window.adminSyncClient.getStatus();
test(
'Admin Sync Client Initialized',
syncStatus.isConnected,
`Realtime: ${syncStatus.useRealtimeListeners}, Listener active: ${syncStatus.syncSignalListenerActive}`
);
} else {
warn('Admin Sync Client Not Available', 'This is normal in service worker context');
}
// Test 7: Check Firebase SDK file sizes
try {
const response1 = await fetch(chrome.runtime.getURL('firebase-app-compat.js'));
const blob1 = await response1.blob();
const size1KB = Math.round(blob1.size / 1024);
const response2 = await fetch(chrome.runtime.getURL('firebase-firestore-compat.js'));
const blob2 = await response2.blob();
const size2KB = Math.round(blob2.size / 1024);
test(
'Firebase SDK Files Present',
size1KB > 25 && size2KB > 300,
`firebase-app-compat.js: ${size1KB}KB, firebase-firestore-compat.js: ${size2KB}KB`
);
} catch (e) {
warn('Could not verify SDK file sizes', e.message);
}
console.log('\n==============================================');
console.log('📊 Test Summary:');
console.log(` ✅ Passed: ${results.passed}`);
console.log(` ❌ Failed: ${results.failed}`);
console.log(` ⚠️ Warnings: ${results.warnings}`);
console.log(` 📝 Total: ${results.tests.length} tests`);
console.log('==============================================\n');
if (results.failed === 0 && results.passed > 0) {
console.log('🎉 All tests passed! Firebase realtime listeners are working correctly.');
console.log('💰 Expected cost savings: $37.44/month (99.7% reduction)');
} else if (results.failed > 0) {
console.log('⚠️ Some tests failed. Check the details above.');
console.log('📖 See REALTIME_IMPLEMENTATION_GUIDE.md for troubleshooting.');
}
console.log('\n🔍 Additional Debug Commands:');
console.log(' - listenerManager?.getStatus() // Check listener status');
console.log(' - window.adminSyncClient?.getStatus() // Check sync status');
console.log(' - await window.getExtensionId() // Get extension ID');
console.log(' - window.debugAdminSync() // Trigger manual sync');
console.log(' - window.forcePresetSync() // Force preset sync\n');
return results;
})();