How I Fixed Electron's "Refused to load the image 'file://...'" CSP Error

2
3
by 2 weeks ago🔹 Drop

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!

Help Push This Message

Share this valuable insight! Help spread useful knowledge and information with your network.

Click to Tweet

Support Our Mission

Help us amplify user voices and push for real change. Your support keeps this platform running and growing.

Every contribution helps us stay independent