How I Fixed Electron's "Refused to load the image 'file://...'" CSP Error
I recently ran into a frustrating issue while building my Electron app:
Whenever I tried to display local images using file:// URLs, the browser console threw a CSP error:
Refused to load the image 'file:///...' because it violates the following Content Security Policy directive...
After some digging, I realized that the default CSP doesn't allow file: URLs for images, even if you use * in default-src. The fix was to explicitly add file: to the img-src directive in my index.html:
<meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' 'unsafe-eval' data: blob:; img-src data: blob: file:;" />
This allowed both local stickers and remote images to load without issues.
Hope this helps someone else stuck on the same problem!