Is there a way to disable web security on Electron (chromium)? Via JavaScript or something?
Asked
Active
Viewed 2.6k times
4 Answers
37
Found it:
new BrowserWindow({webPreferences: {webSecurity: false}});

user2493164
- 1,321
- 3
- 11
- 15
-
Thank you so much! – user10233170 Feb 08 '22 at 21:36
6
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 }
});

Wsiewert
- 61
- 1
- 3
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.

Steven
- 1,996
- 3
- 22
- 33

TranVanThaiSon
- 49
- 1
-
1Welcome to SO. An explanation of how your code solves the problem makes your answer more useful to a greater number of users. – Nick Apr 18 '19 at 08:13
3
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,
});

Sithija Piyuman Thewa Hettige
- 1,768
- 20
- 26