Electron (chromium) disable web security

前端 未结 4 1986
余生分开走
余生分开走 2020-12-17 20:20

Is there a way to disable web security on Electron (chromium)? Via JavaScript or something?

相关标签:
4条回答
  • 2020-12-17 21:01

    In electron's Documentation for BrowserWindow you can use the object 'webPreferences' that comes along with a couple options, 'webSecurity' being one of them. What worked for me to disable web security was the following:

    const win = new BrowserWindow({
      webPreferences: { webSecurity: false }
    });
    
    0 讨论(0)
  • 2020-12-17 21:04
      mainWindow = new BrowserWindow({
    
        'web-preferences': {'web-security': false},
        width: 1800,
        height: 1600,
    
    });
    

    web preferences part fixed the issue for me.if it didn't work try

    app.commandLine.appendSwitch('disable-web-security');
    
    mainWindow = new BrowserWindow({
        'node-integration': 'iframe',
        'web-preferences': {'web-security': false},
        width: 1800,
        height: 1600,
    });
    
    0 讨论(0)
  • 2020-12-17 21:11

      mainWindow = new BrowserWindow({
        height: 563,
        useContentSize: true,
        width: 1000,
        webPreferences: { webSecurity: false }
      })

    import { app, BrowserWindow } from 'electron'
    
      mainWindow = new BrowserWindow({
        height: 563,
        useContentSize: true,
        width: 1000,
        webPreferences: { webSecurity: false }
      })
    

    This is the solution, and it works for me.

    0 讨论(0)
  • 2020-12-17 21:16

    Found it:

    new BrowserWindow({webPreferences: {webSecurity: false}});
    
    0 讨论(0)
提交回复
热议问题