chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.98k stars 279 forks source link

Need a way to filter out X-Frame-Options header #250

Closed donotcodeit closed 4 years ago

donotcodeit commented 4 years ago

I need to display any external website inside of <iframe />.

To avoid cross-origin problem I can use disable-web-security command line argument.

Some sites have set X-Frame-Options header to sameorigin, and will be blocked by CEF. As an option to fix this, it is possible to use reverse proxy and filter out abovementioned header. It is working solution, that was taken from: https://stackoverflow.com/questions/55641868/is-there-a-way-to-avoid-x-frame-options-in-a-cef-windows-chromium-desktop-app

But I'm looking into Chromely implementation and trying to find some handler, that may allow to do same thing, but without external proxy. As I understand CefLoadHandler will be called for <iframe />, but it seems it will not allow to modify response at this point.

I've also checked several other handlers, but looks like they aren't used to handle <iframe /> content. Any suggestions on how to achieve expected behavior?

mattkol commented 4 years ago

The demos can display external websites inside of iframe.

https://github.com/chromelyapps/demo-projects/blob/53ccbdd22eac818ebf96df594f6fc81369965772/regular-chromely/CrossPlatDemo/app/index.html#L131

https://github.com/chromelyapps/demo-projects/blob/53ccbdd22eac818ebf96df594f6fc81369965772/regular-chromely/CrossPlatDemo/app/index.html#L116

https://github.com/chromelyapps/demo-projects/search?q=alldemoframe

The default external request handler has a filter for X-Frame-Options. That is more about an external request, but may help. See this search filter - https://github.com/chromelyapps/Chromely/search?q=X-Frame-Options

donotcodeit commented 4 years ago

This helps, thank you!

I've registered the ExternalRequestSchemeHandlerFactory in container

container.RegisterSingleton(typeof(IChromelySchemeHandlerFactory), "external-resources", typeof(ExternalRequestSchemeHandlerFactory));

and also added UrlScheme

new UrlScheme("external-resources", "http", string.Empty, string.Empty, UrlSchemeType.Custom, false),
new UrlScheme("external-resources", "https", string.Empty, string.Empty, UrlSchemeType.Custom, false),