Electron cannot display local images in dev mode - "Not allowed to load local resource"
See original GitHub issueDescribe the bug
Electron cannot display local images in dev mode since it doesn’t load file:// urls while it is running a page from a non-file URL.
Reproduction: Try to display an image e.g.:
<img src="C:\test\image.png">
Proposed solution:
Disable webSecurity in development mode:
// backgound.js
const window = new BrowserWindow({
webPreferences: {
webSecurity: process.env.NODE_ENV !== 'development',
}
})
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
"Not allowed to load local resource" with file image URL in ...
When inserting an image, my main process copies the image into the notes directory, then returns a file:/// URL to the image file....
Read more >5 Ways To Fix “Not Allowed To Load Local Resource” Error
How to Fix Not Allowed to Load Local Resource Error · Try Disabling the Chrome Security Settings · Change DNS Settings · Clear...
Read more >electron builder not allowed to load local resource - You.com
Describe the bug Electron cannot display local images in dev mode since it doesn't load file:// urls while it is running a page...
Read more >electron not allowed to load local resource mac
Electron by default allows local resources to be accessed by render processes only when their html files are loaded from local sources with...
Read more >How to load images in Electron applications - Debug & Release
Electron application's UIs are loaded through BrowserWindows. By default, a BrowserWindow can't load local resources unless the webPreferences.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@nklayman yeah, but I’m not talking about the images that developer bundles with the app. What if an Electron app need to display images from the user’s disk? And a lot of Electron apps do need to display images from the disk, don’t they?
Try preprending the url with
file://, ie<img src="file://C:/path_to_image.png />.