1

I am working on a CEFPython application that requires me to include some external files like JS or CSS libraries.However any external path (Referring to external libraries present in the same folder and the online resource URL both) mentioned in the HTML file seems to be unacceptable, I am sure am missing a flag to enable external files liking but am unable to figure out which. below is the code to my main function:

def main():
sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
# To change user agent use either "product_version"
# or "user_agent" options. Explained in Tutorial in
# "Change user agent string" section.
settings = {
    # "web_security_disabled": True,
    # "user_agent": "MyAgent/20.00 MyProduct/10.00",

}
cef.Initialize(settings=settings)
browser = cef.CreateBrowserSync(url=html_to_data_uri(HTML_code),
                                window_title="Demo Program")
set_javascript_bindings(browser)
cef.MessageLoop()
cef.Shutdown()
OshoParth
  • 1,492
  • 2
  • 20
  • 44

2 Answers2

1

the "web_security_disabled" setting must be passed in the browser creation, not in the cef initialization.

Example :

settings = {
    "web_security_disabled": True,
}


def launcher(url):
    sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
    cef.Initialize()
    cef.CreateBrowserSync(url=url, window_title="my title", settings=settings)
    cef.MessageLoop()
    cef.Shutdown()
Aqueuse
  • 11
  • 1
0

You cannot mix scripts from different origins, see: https://en.wikipedia.org/wiki/Same-origin_policy

There is --disable-web-security switch that you can try.

If that doesn't work then use "http" url instead of data uri. You can run an internal web server using Python. You can also implement ResourceHandler and serve http content without the need to run a web server, however implementing ResourceHandler correctly is a complex task.

Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56
  • I have tried --disable-web-security switch however passing command line arguments does not seems feasible in my implementation scenario. Also the external resources in my question include the library files in the same directory and also the online resources ( I have updated the same in the question too). Also could you please share a code snippet or document reference for "http" url use and Resource handler implementation. – OshoParth Jun 03 '19 at 04:46
  • See documentation for ResourceHandler. You can also try file:// protocol and BrowserSettings.`file_access_from_file_urls_allowed` and `universal_access_from_file_urls_allowed` options. – Czarek Tomczak Jun 03 '19 at 08:42
  • I tried passing the above mentioned settings in the settings object, as mentioned in the question too but it gives error, could you please share a example for passing the browser settings ? – OshoParth Jun 04 '19 at 04:30
  • @OshoParth See the Tutorial, documentation and examples. – Czarek Tomczak Jun 04 '19 at 08:45