添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Electron should be able to load local resources with enabled webSecurity #23393

@aleksey-hoffman

Description

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • Issue Details

    An Electron app can only display local images (located on the computer) with webSecurity: false :

    Renderer process

    <img src="file://C:/test.jpg">

    Main process

    mainWindow = new BrowserWindow({
      webPreferences: {
        webSecurity: false
    

    It doesn't make sense to completely disable all security features just to be able to load local images / videos, etc. There's should be a property that allows the app to load local resources without disabling all security features.

    Electron Version: All

    Operating System: All

    Expected Behavior

    Electron should be able to load local resources without disabling all security features.

    Actual Behavior

    Electron cannot load local resources without disabling all security features.

    To Reproduce

    Create an app with https://github.com/nklayman/vue-cli-plugin-electron-builder

    vue create my-app
    cd my-app
    vue add electron-builder
    

    Then add an image, e.g. in App.vue

    <img src="file://C:/test.png">
    yarn electron:build

    Open /dist_electron and install the app. Then open the console and see the error:

    image