Electron (chromium) disable web security

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

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

回答1:

Found it:

new BrowserWindow({webPreferences: {webSecurity: false}}); 


回答2:

  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, }); 


回答3:

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 } }); 


回答4:

  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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!