question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Electron cannot display local images in dev mode - "Not allowed to load local resource"

See original GitHub issue

Describe 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:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
alexhx5commented, Nov 24, 2018

@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?

2reactions
nklaymancommented, Jun 7, 2019

Try preprending the url with file://, ie <img src="file://C:/path_to_image.png />.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found