Created
August 2, 2022 22:46
-
-
Save alienator88/1ddad8bd4319cbfae4ad420828c976a5 to your computer and use it in GitHub Desktop.
Bypass CORS safely in Electron apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainWindow.webContents.session.webRequest.onBeforeSendHeaders( | |
(details, callback) => { | |
callback({ requestHeaders: { Origin: '*', ...details.requestHeaders } }); | |
}, | |
); | |
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => { | |
callback({ | |
responseHeaders: { | |
'Access-Control-Allow-Origin': ['*'], | |
// We use this to bypass headers | |
'Access-Control-Allow-Headers': ['*'], | |
...details.responseHeaders, | |
}, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment