ATlast — you'll never need to find your favorites on another platform again. Find your favs in the ATmosphere.
atproto

fix critical messaging bug: onMessage was discarding return values

The onMessage wrapper in messaging.ts was only sending {success: true}
instead of the actual handler return value. This caused the popup to
receive undefined state even though the background worker was correctly
storing it.

Changes:
- messaging.ts: Changed onMessage to forward handler return values
- background service-worker.ts: Added comprehensive logging
- popup.ts: Added state change listener and detailed logging

This fixes the issue where popup showed 'Go to...' even when on the
following page.

byarielm.fyi 0718100f 5df64380

verified
Changed files
+28 -7
packages
extension
src
background
lib
popup
+7 -1
packages/extension/src/background/service-worker.ts
··· 53 53 * Update state from content script 54 54 */ 55 55 async function handleStateUpdate(newState: Partial<ExtensionState>): Promise<void> { 56 + console.log('[Background] 📥 Received state update:', newState); 56 57 const currentState = await getState(); 58 + console.log('[Background] 📋 Current state before update:', currentState); 57 59 const updatedState = { ...currentState, ...newState }; 58 60 await setState(updatedState); 59 - console.log('[Background] State updated:', updatedState); 61 + console.log('[Background] ✅ State updated successfully:', updatedState); 62 + 63 + // Verify the state was saved 64 + const verifyState = await getState(); 65 + console.log('[Background] 🔍 Verified state from storage:', verifyState); 60 66 } 61 67 62 68 /**
+4 -3
packages/extension/src/lib/messaging.ts
··· 105 105 * Listen for messages 106 106 */ 107 107 export function onMessage( 108 - handler: (message: Message, sender: chrome.runtime.MessageSender) => void | Promise<void> 108 + handler: (message: Message, sender: chrome.runtime.MessageSender) => any | Promise<any> 109 109 ): void { 110 110 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { 111 111 const result = handler(message, sender); 112 112 113 113 // Handle async handlers 114 114 if (result instanceof Promise) { 115 - result.then(() => sendResponse({ success: true })) 115 + result.then((data) => sendResponse(data)) 116 116 .catch(error => sendResponse({ success: false, error: error.message })); 117 117 return true; // Keep message channel open for async response 118 118 } 119 119 120 - sendResponse({ success: true }); 120 + // Send sync result 121 + sendResponse(result); 121 122 }); 122 123 }
+17 -3
packages/extension/src/popup/popup.ts
··· 43 43 * Update UI based on extension state 44 44 */ 45 45 function updateUI(state: ExtensionState): void { 46 - console.log('[Popup] Updating UI:', state); 46 + console.log('[Popup] 🎨 Updating UI with state:', state); 47 + console.log('[Popup] 🎯 Current status:', state.status); 48 + console.log('[Popup] 🌐 Platform:', state.platform); 49 + console.log('[Popup] 📄 Page type:', state.pageType); 47 50 48 51 switch (state.status) { 49 52 case 'idle': ··· 189 192 * Initialize popup 190 193 */ 191 194 async function init(): Promise<void> { 192 - console.log('[Popup] Initializing...'); 195 + console.log('[Popup] 🚀 Initializing popup...'); 193 196 194 197 // Get current state 198 + console.log('[Popup] 📡 Requesting state from background...'); 195 199 const state = await sendToBackground<ExtensionState>({ 196 200 type: MessageType.GET_STATE 197 201 }); 198 202 203 + console.log('[Popup] 📥 Received state from background:', state); 199 204 updateUI(state); 200 205 201 206 // Set up event listeners ··· 208 213 updateUI(state); 209 214 }); 210 215 216 + // Listen for storage changes (when background updates state) 217 + chrome.storage.onChanged.addListener((changes, areaName) => { 218 + if (areaName === 'local' && changes.extensionState) { 219 + const newState = changes.extensionState.newValue; 220 + console.log('[Popup] 🔄 Storage changed, new state:', newState); 221 + updateUI(newState); 222 + } 223 + }); 224 + 211 225 // Poll for updates if currently scraping 212 226 if (state.status === 'scraping') { 213 227 pollForUpdates(); 214 228 } 215 229 216 - console.log('[Popup] Ready'); 230 + console.log('[Popup] ✅ Popup ready'); 217 231 } 218 232 219 233 // Initialize when DOM is ready