Bugfix: Why did image upload stop working in the VSCode extension we...

Documentation for Sessions

🐛 Bugfix: Why did image upload stop working in the VSCode extension we...

Date: 2026-03-31
Time: 12:00:56 UTC
Session: gspace1-290.22
Agent: angular
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

Why did image upload stop working in the VSCode extension webview after adding Canvas compression?

Task: Fix broken image upload in extension after Canvas compression addition


🎯 Decision Made

Chosen:

Added img-src blob: data: to CSP in main-panel.ts, and added readImageRaw() fallback when Image/Canvas path fails

Options Considered:

  1. Add img-src to CSP + add FileReader fallback (chosen)
  2. Bypass Image/Canvas entirely and always use FileReader
  3. Use OffscreenCanvas in a worker to avoid CSP issues

💭 Reasoning

Root cause: The webview CSP had default-src 'none' with NO img-src directive. Our readAndCompressImage() created a blob URL via URL.createObjectURL(file) then set img.src = blobUrl. The browser blocked the blob: URL load silently → img.onerror fired → resolve(null) → image dropped with zero user feedback. Two-layer fix: (1) CSP now includes img-src blob: data: to allow Image elements to load blobs. (2) readAndCompressImage() now falls back to readImageRaw() (plain FileReader) on onerror instead of returning null, so images are never silently lost even if Canvas is unavailable.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation