cefsharp / Questions-and-Support

Use this repository to ask CefSharp specific questions
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

ResourceHandler CORS problem #60

Closed ray007 closed 4 years ago

ray007 commented 4 years ago

Bug Report

I have updated my application to use CefSharp 85, and suddenly my scheme-handler which takes data from POST requests to a http: address to cache it in the file-system fails with CORS errors.

Interestingly, GET requests to a custom scheme (prjdata:) still work fine.

If it makes a difference, my application shown in the WPF view is also served by a custom-scheme myapp:.

I know that my scheme-handler gets called and executed without problems, just the reponse to the browser goes missing. The error message in the console is

Access to XMLHttpRequest at 'http://prjdata.cefsharp/Settings11/Menu.zml' from origin 'myapp://cefsharp' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

No errors visible in visual studio. Not sure if it's relevant, but in debug.log I find several lines

[0124/101807.789:ERROR:registration_protocol_win.cc(56)] CreateFile: The system cannot find the file specified. (0x2)
amaitland commented 4 years ago

What version did you upgrade from?

Nothing here that would indicate a bug in CefSharp, more likely a change in CEF/Chromium.

ray007 commented 4 years ago

It worked with CEF/CefSharp 84, and does not work anymore with 85.

amaitland commented 4 years ago

You can compare the two releases https://github.com/cefsharp/CefSharp/compare/v84.4.10...v85.3.130

I only remember one change to ResourceHandler, you can easily remove the header for testing purposes.

The fact that it works for GET requests and not POST it's more likely a change in CEF/Chromium and not CefSharp specific.

I'd personally try switching to using the https scheme and registering the schemehandlerfactory with a domain name.

ray007 commented 4 years ago

I already did look through history and didn't see anything I would think could cause this, but then I do not know the code well enough to really judge that.

The GET requests go to a custom protocol scheme, I only use the http protocol for storing data to cache since otherwise I do not get POST data in the scheme handler. I also have a line

settings.CefCommandLineArgs.Add("disable-web-security", "true");

in my code so I do not need CORS anywhere else, maybe there was a change with web-security somewhere? I also added for testing

settings.CefCommandLineArgs.Add("disable-oor-cors", "true");

but that didn't change anything.

I also wouldn't care if the scheme handler did use CORS if it sent the right headers in the response, but settings IsCorsEnabled and IsStandard to true doesn't do that. Am I missing something?

Or is there another way to efficiently get large amount of binary data from the js-app to the C# layer?

amaitland commented 4 years ago

Have you tried registering your schemehandlerfactory using https and specifying a domain? You can specify a subdomain of the domain you are sending requests from.

See https://github.com/cefsharp/CefSharp/blob/cefsharp/85/CefSharp.Example/CefExample.cs#L183 for an example.

If you have and that didn't work then I'd suggest moving the conversation over to https://magpcss.org/ceforum/index.php see if ther have been any other reports.

ray007 commented 4 years ago

It's very strange. I have changed all my scheme-handlers to http, with the project data handler using a subdomain of the application code handler. The GET requests for existing cache data still work fine (without CORS), the POST requests to put new data into the cache still fail with a CORS error.

ray007 commented 4 years ago

Update: interestingly, adding

settings.CefCommandLineArgs.Add("disable-features", "OutOfBlinkCors");

makes things work again.

amaitland commented 4 years ago

Question asked at https://magpcss.org/ceforum/viewtopic.php?f=18&t=17968