Im trying to show a website in electron, but it appears the error that , x-frame-option is in sameorigin, i have read a lot of code about how bypass it, but i have not idea where put it, if in the main, or in what pass, someone can help me a little here? the link is this one
2 Answers
Use below lines after initialized BrowserWindow
instance:
win.webContents.session.webRequest.onHeadersReceived({ urls: [ "*://*/*" ] },
(d, c)=>{
if(d.responseHeaders['X-Frame-Options']){
delete d.responseHeaders['X-Frame-Options'];
} else if(d.responseHeaders['x-frame-options']) {
delete d.responseHeaders['x-frame-options'];
}
c({cancel: false, responseHeaders: d.responseHeaders});
}
);
But not recommended, just embed for your testing purpose.
Typescript version... You best only allow this on some URLs. :D
//remove X-Frame-Options headers on all incoming requests.
mainWindow.webContents.session.webRequest.onHeadersReceived(
{ urls: ["*://*/*"] },
(details, callback) => {
if (details && details.responseHeaders) {
if (details.responseHeaders["X-Frame-Options"]) {
delete details.responseHeaders["X-Frame-Options"]
} else if (details.responseHeaders["x-frame-options"]) {
delete details.responseHeaders["x-frame-options"]
}
}
callback({ cancel: false, responseHeaders: details.responseHeaders })
}
)