CORS question for custom resource handler

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CORS question for custom resource handler

Postby sbush1310 » Sat Sep 24, 2022 1:06 am

I have a custom resource handler registered for "res" as:
Code: Select all
registrar->AddCustomScheme("res", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_LOCAL);


and all has generally been working well. However, we recently added some web fonts to the internal css and are getting this error:

949:1 Access to font at 'res://myapp/E%3A%5Cdev%5CSample.exe/SAMPLE_WEB_FONT' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
SAMPLE_WEB_FONT:1 Failed to load resource: net::ERR_FAILED

Looking at the code comments for AddCustomScheme:
Code: Select all
// See cef_scheme_options_t for possible values for |options|.


Looking at cef_scheme_options_t for CEF_SCHEME_OPTION_LOCAL:
Code: Select all
///
  // If CEF_SCHEME_OPTION_LOCAL is set the scheme will be treated with the same
  // security rules as those applied to "file" URLs. Normal pages cannot link to
  // or access local URLs. Also, by default, local URLs can only perform
  // XMLHttpRequest calls to the same URL (origin + path) that originated the
  // request. To allow XMLHttpRequest calls from a local URL to other URLs with
  // the same origin set the CefSettings.file_access_from_file_urls_allowed
  // value to true (1). To allow XMLHttpRequest calls from a local URL to all
  // origins set the CefSettings.universal_access_from_file_urls_allowed value
  // to true (1).
  ///
  CEF_SCHEME_OPTION_LOCAL = 1 << 1,


However, file_access_from_file_urls_allowed and universal_access_from_file_urls_allowed do not seem to exist any longer?

So, what is the preferred way to handle this?

Thanks in advance!
sbush1310
Techie
 
Posts: 16
Joined: Thu Jan 07, 2016 5:15 pm

Re: CORS question for custom resource handler

Postby magreenblatt » Sat Sep 24, 2022 11:56 am

You have a few options:

1. Don’t use CEF_SCHEME_OPTION_LOCAL, or
2. Encode the web fonts in the CSS directly (example)
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 75 guests

cron