Sometimes we try to do http requests from Electron to any page and it seems to be blocked by the "Browser engine" that comes with the renderer proccess.
There's one solution
- Change the BrowserWindow security config
Within the main process, we'll search for new BrowserWindow
. That's the window declaration.
Inside it, we'll search for webPreferences
, and change or add the websSecurity: false
property.
mainWindow = new BrowserWindow({
width: 1000,
height: 600,
//... more code
webPreferences: {
// ... more code
// Add the following line.
webSecurity: false,
}
})
- Disabling CORS speciffically
Then, on the instance, the app
variable has the main app.
So, to disable the CORS, in any part of the main proccess disable the CORS feaature with the next line.
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors')
And that's all! Re-run your app to see the changes.
Note: in Quasar the main process is in
src-electron/main-process/electron-main.js