Electron - Not allowed to load local resource

后端 未结 10 1886
夕颜
夕颜 2020-12-28 14:05

Evening,
I\'m looking into using electron to package an existing angular2 build. I thought I had a dry run working but the actual packaging seems to be failing (see fina

相关标签:
10条回答
  • 2020-12-28 14:28

    I had the same problem. This worked for me

    // and load the index.html of the app.
      window.loadURL(url.format({
        pathname: path.join(__dirname, 'dist/index.html'), // important
        protocol: 'file:',
        slashes: true,
        // baseUrl: 'dist'
      }));
    
    0 讨论(0)
  • 2020-12-28 14:34

    this works for me on linux

     newWindow.loadFile(`${__dirname}/index.html`);
    

    you can add this to view the directory of your main.js and from there navigate to the index.html. console.log(__dirname)

    0 讨论(0)
  • 2020-12-28 14:35

    I had the exact problem when i tried to build my app with electron-builder...

    What worked for me was in package.json file i built with ng build then runed electron-builder

    "scripts": {
     ...
    "build-installer": "ng build --prod && electron-builder"
    },
    

    and in the index.html changed base href to

     <base href="">
    
    0 讨论(0)
  • 2020-12-28 14:37

    Problem may be the invalid path in main.js, correct it if necessary

    0 讨论(0)
  • 2020-12-28 14:38

    Just change the BrowserWindow' options: new BrowserWindow({ webPreferences: { webSecurity: false } }) If window's url points to a remote source, like http://..., browser will not allow to load local resource, unless you set the options above.

    0 讨论(0)
  • 2020-12-28 14:39

    I had the same issue and my mistake was the win.loadURL was not correct (loadURL tried to load a file who doesn't exist). Be sure your url is correct otherwise you will get an error.

    0 讨论(0)
提交回复
热议问题