fix: Issue with electron not displaying site

This commit is contained in:
LukeGus
2025-10-31 14:47:13 -05:00
parent 0a125a3246
commit 79419420bf
3 changed files with 40 additions and 3 deletions

View File

@@ -64,6 +64,41 @@ function createWindow() {
mainWindow.loadFile(indexPath);
}
// Allow iframes to load from any origin by removing X-Frame-Options headers
mainWindow.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {
const headers = details.responseHeaders;
// Remove headers that block iframe embedding
if (headers) {
delete headers["x-frame-options"];
delete headers["X-Frame-Options"];
// Modify CSP to allow framing
if (headers["content-security-policy"]) {
headers["content-security-policy"] = headers["content-security-policy"]
.map(value => value.replace(/frame-ancestors[^;]*/gi, ''))
.filter(value => value.trim().length > 0);
if (headers["content-security-policy"].length === 0) {
delete headers["content-security-policy"];
}
}
if (headers["Content-Security-Policy"]) {
headers["Content-Security-Policy"] = headers["Content-Security-Policy"]
.map(value => value.replace(/frame-ancestors[^;]*/gi, ''))
.filter(value => value.trim().length > 0);
if (headers["Content-Security-Policy"].length === 0) {
delete headers["Content-Security-Policy"];
}
}
}
callback({ responseHeaders: headers });
}
);
mainWindow.once("ready-to-show", () => {
mainWindow.show();
});