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

1

2 Answers 2

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.

1

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 })
    }
  )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.