A browser extension that lets you summarize any webpage and ask questions using AI.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Cache follow-up suggestions and fix their positioning after chat messages

+37 -4
+37 -4
popup/popup.js
··· 53 53 const CONTENT_CACHE_PREFIX = "content_cache_"; 54 54 const CHAT_CACHE_PREFIX = "chat_cache_"; 55 55 const TRUNCATION_CACHE_PREFIX = "truncation_cache_"; 56 + const SUGGESTIONS_CACHE_PREFIX = "suggestions_cache_"; 56 57 57 58 // ── Prompts ────────────────────────────────────────────────── 58 59 const SYSTEM_PROMPT_SUMMARIZER = ··· 267 268 DETAILED_SUMMARY_CACHE_PREFIX + currentTabId, 268 269 CONTENT_CACHE_PREFIX + currentTabId, 269 270 CHAT_CACHE_PREFIX + currentTabId, 271 + SUGGESTIONS_CACHE_PREFIX + currentTabId, 270 272 ]); 271 273 272 274 const cachedQuickSummary = cached[QUICK_SUMMARY_CACHE_PREFIX + currentTabId]; ··· 274 276 cached[DETAILED_SUMMARY_CACHE_PREFIX + currentTabId]; 275 277 const cachedContent = cached[CONTENT_CACHE_PREFIX + currentTabId]; 276 278 const cachedChat = cached[CHAT_CACHE_PREFIX + currentTabId]; 279 + const cachedSuggestions = cached[SUGGESTIONS_CACHE_PREFIX + currentTabId]; 277 280 278 281 resetUI(); 279 282 summarizeBtn.disabled = true; ··· 302 305 if (cachedChat && cachedChat.messages) { 303 306 chatHistory = cachedChat.messages; 304 307 } 308 + // Restore suggestions if they exist 309 + if (cachedSuggestions && cachedSuggestions.suggestions) { 310 + generatedSuggestions = cachedSuggestions.suggestions; 311 + } 305 312 306 313 // Build combined display if we have any summaries 307 314 if (quickSummary || detailedSummary) { ··· 376 383 QUICK_SUMMARY_CACHE_PREFIX + currentTabId, 377 384 DETAILED_SUMMARY_CACHE_PREFIX + currentTabId, 378 385 CHAT_CACHE_PREFIX + currentTabId, 386 + SUGGESTIONS_CACHE_PREFIX + currentTabId, 379 387 ]); 380 388 quickSummary = ""; 381 389 detailedSummary = ""; 382 390 chatHistory = []; 391 + generatedSuggestions = []; 383 392 } 384 393 await generateQuickSummary(); 385 394 }); ··· 541 550 QUICK_SUMMARY_CACHE_PREFIX + currentTabId, 542 551 DETAILED_SUMMARY_CACHE_PREFIX + currentTabId, 543 552 CHAT_CACHE_PREFIX + currentTabId, 553 + SUGGESTIONS_CACHE_PREFIX + currentTabId, 544 554 ]); 545 555 quickSummary = ""; 546 556 detailedSummary = ""; ··· 553 563 554 564 resultContainer.appendChild(buttonContainer); 555 565 556 - // Add suggestions below summary actions 557 - renderSuggestions(); 558 - 559 566 // Hide footer after summary is shown 560 567 footer.classList.add("hidden"); 561 568 562 569 showChat(); 563 570 renderChatMessages(); 571 + 572 + // Render suggestions after chat messages if chat history exists 573 + renderSuggestions(chatHistory.length === 0); 564 574 } 565 575 566 576 function showChat() { ··· 897 907 url: currentTabUrl, 898 908 }, 899 909 }); 900 - // Clear any old detailed summary cache since we're regenerating 910 + // Clear any old detailed summary and suggestions cache since we're regenerating 901 911 chrome.storage.session.remove([ 902 912 DETAILED_SUMMARY_CACHE_PREFIX + currentTabId, 913 + SUGGESTIONS_CACHE_PREFIX + currentTabId, 903 914 ]); 904 915 } 905 916 } ··· 986 997 987 998 // Render the generated suggestions (or fallback) 988 999 renderSuggestions(); 1000 + 1001 + // Cache the suggestions for this tab 1002 + if (currentTabId && generatedSuggestions.length > 0) { 1003 + chrome.storage.session.set({ 1004 + [SUGGESTIONS_CACHE_PREFIX + currentTabId]: { 1005 + suggestions: generatedSuggestions, 1006 + url: currentTabUrl, 1007 + timestamp: Date.now(), 1008 + }, 1009 + }); 1010 + } 989 1011 } catch (error) { 990 1012 clearTimeout(timeoutId); 991 1013 console.error("Failed to generate suggestions:", error); ··· 1095 1117 } 1096 1118 1097 1119 renderSuggestions(false); 1120 + 1121 + // Cache the suggestions for this tab 1122 + if (currentTabId) { 1123 + chrome.storage.session.set({ 1124 + [SUGGESTIONS_CACHE_PREFIX + currentTabId]: { 1125 + suggestions: generatedSuggestions, 1126 + url: currentTabUrl, 1127 + timestamp: Date.now(), 1128 + }, 1129 + }); 1130 + } 1098 1131 } catch (error) { 1099 1132 clearTimeout(timeoutId); 1100 1133 console.error("Failed to generate chat suggestions:", error);