Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cefpython app with html/js files in local filesystem

I'm trying to make a hybrid python-js application with cefpython.

I would like to have:

  • JS and HTML files local to the cef python app (e.g. in './html', './js', etc)
  • Load one of the HTML files as the initial page
  • Avoid any CORS issues with files accessing each other (e.g. between directories)

The following seems to work to load the first page:

browser = cef.CreateBrowserSync(url='file:///html/index.html',
                                window_title="Rulr 2.0")

However, I then hit CORS issues. Do I need to run a webserver also? Or is there an effective pattern for working with local files?

like image 278
Elliot Woods Avatar asked Aug 04 '18 09:08

Elliot Woods


1 Answers

Try passing "disable-web-security" switch to cef.Initialize or set BrowserSettings.web_security_disabled.

Try also setting BrowserSettings.file_access_from_file_urls_allowed and BrowserSettings.universal_access_from_file_urls_allowed.

There are a few options in CEF for loading custom content and that can be used to load filesystem content without any security restrictions. There is a resource handler, a scheme handler and a resource manager. In CEF Python only resource handler is currently available. There is the wxpython-response.py example on README-Examples.md page.

Resource manager is a very easy API for loading various content, it is to be implemented in Issue #418 (PR is welcome): https://github.com/cztomczak/cefpython/issues/418

For scheme handler see Issue #50: https://github.com/cztomczak/cefpython/issues/50

Additionally there is also GetResourceResponseFilter in upstream CEF which is an easier option than resource handler, to be implemented via Issue #229: https://github.com/cztomczak/cefpython/issues/229

You could also run an internal web server inside your app (easy to do with Python) and serve files that way. Upstream CEF also has a built-in web server functionality, however I don't think this will be exposed in cefpython, as it's already easy to set up web server in Python.

like image 156
Czarek Tomczak Avatar answered Oct 18 '22 20:10

Czarek Tomczak