diff --git a/extension/src/background/index.ts b/extension/src/background/index.ts index 4fea757..6ba46b3 100644 --- a/extension/src/background/index.ts +++ b/extension/src/background/index.ts @@ -9,7 +9,19 @@ const API_BASE = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api chrome.runtime.onMessage.addListener((message: { type: string; payload?: any }, _sender: chrome.runtime.MessageSender, sendResponse: (response?: any) => void) => { if (message.type === 'SHOW_INSIGHT') { - console.log('Received tweet data in background:', message.payload); + console.log('[InsightReply Background] Received SHOW_INSIGHT data:', message.payload); + if (_sender.tab?.id) { + console.log(`[InsightReply Background] Forwarding SHOW_INSIGHT to tab ${_sender.tab.id}`); + chrome.tabs.sendMessage(_sender.tab.id, message, (response) => { + if (chrome.runtime.lastError) { + console.error('[InsightReply Background] Error forwarding message to tab:', chrome.runtime.lastError); + } else { + console.log('[InsightReply Background] Successfully forwarded to tab, response:', response); + } + }); + } + sendResponse({ success: true, forwarded: !!_sender.tab?.id }); + return true; } if (message.type === 'FETCH_CUSTOM_STRATEGIES') { diff --git a/extension/src/content/index.ts b/extension/src/content/index.ts index de75472..ec88edb 100644 --- a/extension/src/content/index.ts +++ b/extension/src/content/index.ts @@ -52,7 +52,14 @@ const extractTweetData = (tweetElement: HTMLElement): TweetData | null => { const authorElement = tweetElement.querySelector('[data-testid="User-Name"]'); const linkElement = tweetElement.querySelector('time')?.parentElement as HTMLAnchorElement; - if (!textElement || !authorElement || !linkElement) return null; + if (!textElement || !authorElement || !linkElement) { + console.debug('[InsightReply] Missing elements for tweet extraction:', { + hasText: !!textElement, + hasAuthor: !!authorElement, + hasLink: !!linkElement + }); + return null; + } const getStat = (testid: string) => { const el = tweetElement.querySelector(`[data-testid="${testid}"]`); @@ -146,19 +153,40 @@ const injectInsightButton = (tweetElement: HTMLElement) => { btnContainer.style.marginLeft = '12px'; btnContainer.style.cursor = 'pointer'; - btnContainer.innerHTML = ` -