I'm taking my first steps using CEF. I know some Python so I'm using CEFPython. I'm making a simple app processing some data from a local DB with Python and then writing that data to a JSON file. The goal is to finally show the JSON data nicely using HTML, JS and CSS.
I started modifying the tutorial.py file from the Github repo. First, I putted the HTML code in a variable and I'm reading it this way:
HTML_code = open("test.html", "r").read()
I then create a browser:
browser = cef.CreateBrowserSync(url=html_to_data_uri(HTML_code),
settings = browser_settings)
Now, in the header of the HTML, I call the JSON file this way:
<script src="test.json"></script>
I can render the website, along with the JSON file, perfectly on Chrome. But with CEFPython, I can't load the JSON file this way. I'm guessing there might be some CORS issues.
I tried modifying the browser and cef.Initialize settings, as suggested on this answer. But these changes seem to have no effect. This is how I tried setting them up:
switches = {
"disable-web-security": ""
}
browser_settings = {
"file_access_from_file_urls_allowed": "",
"universal_access_from_file_urls_allowed": "",
"web_security_disabled": ""
}
cef.Initialize(settings=settings, switches=switches)
set_global_handler()
HTML_code = open("test.html", "r").read()
browser = cef.CreateBrowserSync(url=html_to_data_uri(HTML_code),
settings = browser_settings)
All files (the python script, the HTML and the JSON) are in the same folder. I'm running it by using "python test.py" from the terminal on that folder. I don't want to call the files by using the full path since this program is gonna be used by other people that will not have the same path.
How can I load the JSON file correctly?