4

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

https://mobile.bet365.com

DarknessDemon
  • 49
  • 1
  • 3
  • Possible duplicate of [How to set 'X-Frame-Options' on iframe?](https://stackoverflow.com/questions/27358966/how-to-set-x-frame-options-on-iframe) – Quentin Jan 08 '19 at 13:40

2 Answers2

7

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.

dphans
  • 1,543
  • 19
  • 20
0

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 })
    }
  )
Max Barrass
  • 2,776
  • 1
  • 19
  • 10