Skip to content

Commit b9b7d2c

Browse files
Add option to remove "x-frame-options" and "content-security-policy" response headers (#2963)
Many users like me do have the problem that they want to embed other sites to their mirror by "iframe". As some developers set the "x-frame-options" and "content-security-policy" for security reasons these sites can not be embedded. Electron provides the "webview" element additionally to "iframe" which allows to embed these sites although. The main difference is that a new process is started which handles the "webview" element. BUT: As the "webview" process needs to be started and is isolated "webview" is slower and the elements can not be accessed from the embedding website. As an alternative i implemented a small callback function in electron.js which removes the response headers that forbid the embedding. The removing can be controlled with the new config options: * ignoreXOriginHeader * ignoreContentSecurityPolicy
1 parent 0b01e9d commit b9b7d2c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Special thanks to: @rejas, @sdetweil, @MagMar94
1919
- Added css class names "today" and "tomorrow" for default calendar
2020
- Added Collaboration.md
2121
- Added new github action for dependency review (#2862)
22+
- Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy"
2223

2324
### Removed
2425

js/electron.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ function createWindow() {
103103
}, 1000);
104104
});
105105
}
106+
107+
//remove response headers that prevent sites of being embedded into iframes if configured
108+
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
109+
let curHeaders = details.responseHeaders;
110+
if (config["ignoreXOriginHeader"] || false) {
111+
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/x-frame-options/i.test(header[0])));
112+
}
113+
114+
if (config["ignoreContentSecurityPolicy"] || false) {
115+
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/content-security-policy/i.test(header[0])));
116+
}
117+
118+
callback({ responseHeaders: curHeaders });
119+
});
106120
}
107121

108122
// This method will be called when Electron has finished

0 commit comments

Comments
 (0)