- GET /api/tags from background script: 200 ✓
- POST /api/chat from background script: 403 ✗
- POST /api/chat from curl: 200 ✓
Root Cause: Thunderbird background script has restricted fetch context. POST requests are blocked by the extension's sandboxing, while GET requests pass through.
Use popup windows (browser context) for Ollama POST requests instead of direct fetch from background script.
- Popup context runs in full browser environment (like a regular tab)
- No sandboxing restrictions on POST requests
- Web Worker in popup handles actual API communication
User clicks "Analyze"
↓
background.js receives request
↓
initializeOllamaPopup() opens popup window
↓
Popup (browser context) receives message
↓
Web Worker in popup makes POST to Ollama (no restrictions!)
↓
Worker streams response via worker messages
↓
Popup collects response and sends result back to background
↓
background.js processes result and applies label
- initializeOllamaPopup(): Now waits for popup to send back analysis result
- Listens for
ollama_analysis_result_message with result - Automatically closes popup after analysis completes
- 30-second timeout for safety
- analysisResult variable: Stores the accumulated response
- sendResultToBackground(): Sends result back via message after analysis completes
- Listener for
ollama_analyzecommand from background
- background.js calls
initializeOllamaPopup() - Popup opens and sends
ollama_popup_ready_message - background.js sends
ollama_analyzemessage with prompt - Popup's worker processes with Ollama (no 403!)
- Worker sends tokens via
newTokenmessages - When done, popup sends
ollama_analysis_result_message - background.js receives result and continues processing
- Popup auto-closes
- Popup runs in normal browser context (not restricted extension background)
- No sandboxing = POST requests work normally
- Same localhost/Ollama as before, but from unrestricted context
The new XPI should now:
- Open a small popup window when analyzing
- See "Processing with Ollama..." status
- Collect response successfully
- Auto-close popup
- Apply label to email
No more 403 errors!
Files Updated:
- background.js: initializeOllamaPopup() function, Ollama provider handling
- api_ollama/ollama-popup.js: Result collection and sending
- manifest.json: Already had web_accessible_resources
Version: 1.2.3.2 (popup-based Ollama analysis) Date: 2026-01-16 00:48