JCEF & CORS

Having problems with building or using the JCEF Java binding? Ask your questions here.

JCEF & CORS

Postby tasse » Mon Oct 02, 2017 8:33 am

Hello everybody,

I am trying to build load a texture with ThreeJS within JCEF.
I have an issue with CORS though, always getting an error message like:

Access to Image at 'img://textures/texture1.jpg' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.


I tried the following:

- Starting the cef app with the flags
Code: Select all
         -–disable-web-security
         --allow-file-access-from-files

      like cefApp = CefApp.getInstance(new String[]{"-–disable-web-security", "--allow-file-access-from-files"});


I tried all 4 combinations here with the following options:


- Directly loading the jpg in the js code (full path)

Code: Select all
      Error:
         
         file:///static.html: Access to Image at 'file:///my/textures/texture1.jpg' from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.


- Setting up a webservice @ localhost
Code: Select all
      Error:

         2017-10-02 15:30:40 WARN 05E [CefLogDisplayHandler.onConsoleMessage]: [0] file:///static.html: Access to Image at 'http://localhost:8000/texture1.jpg' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.


- Registering a scheme "img://example/"
Code: Select all
      Error:
   file:///static.html: Access to Image at 'img://example/texture1.jpg' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.



Really appreciate any help!

BR
Last edited by tasse on Wed Oct 04, 2017 4:06 pm, edited 2 times in total.
tasse
Newbie
 
Posts: 3
Joined: Mon Oct 02, 2017 8:15 am

Re: JCEF, ThreeJS & CORS

Postby magreenblatt » Mon Oct 02, 2017 3:52 pm

magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: JCEF, ThreeJS & CORS

Postby tasse » Wed Oct 04, 2017 2:16 am

magreenblatt wrote:Don't use the file scheme. See https://bitbucket.org/chromiumembedded/ ... t-handling


Hi magreenblatt, thanks for the reply.
What should I use then? Are you suggesting I use the http scheme and intercept the request?

thanks

// edit: Tried using a CefResourceHandlerAdapter that returns a CefResourceHandlerAdapter in the getResourceHandler(browser, request) function. Result is the same though.

// edit2: Tried modifiying the CefRequest in onBeforeResourceLoad(..) by setting the images bytes into a postData object. Error too though.

Any further information?

Why is neither AddCrossOriginWhitelistEntry nor any websecurity disabling option available in JCEF anymore?
tasse
Newbie
 
Posts: 3
Joined: Mon Oct 02, 2017 8:15 am

Re: JCEF, ThreeJS & CORS

Postby magreenblatt » Wed Oct 04, 2017 8:47 am

Read the documentation on the CefSchemeRegistrar::AddCustomScheme method. You may be registering the scheme incorrectly, and/or your localhost server should return Access-Control-Allow-Origin headers.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: JCEF, ThreeJS & CORS

Postby tasse » Wed Oct 04, 2017 9:39 am

magreenblatt wrote:Read the documentation on the CefSchemeRegistrar::AddCustomScheme method. You may be registering the scheme incorrectly, and/or your localhost server should return Access-Control-Allow-Origin headers.


Hi,
yes, just figured out that I was missing the last part.
Adding

Code: Select all
map.put("Access-Control-Allow-Origin", "*");


to the response header fixed it!

Thanks!
tasse
Newbie
 
Posts: 3
Joined: Mon Oct 02, 2017 8:15 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 21 guests