How to Serve Resource Files Locally to JCEF

I am trying to integrate a webview as part of my plugin development. I have created a react application for the same and I am passing the index.html file as a resource to the plugin to render the webview using the JCEF framework by JBCefBrowser.loadURL(file://path_to_html). The resource html is served using the file:// protocol. While doing this I am facing the following issue.

Access to script at 'file://./assets/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, chrome, https, chrome-untrusted. source: 'file://./index.html'

Here index.js is referenced form index.html through <script type="module" src="./assets/index.js"></script>

Found one blog here to that serves files by hosting it locally: https://timweiss.net/blog/2024-01-06-serving-files-from-resources-intellij-cef/. The method recommended in the blog is working, but I was wondering if there were alternatives to render local files in a web view other than using a local server??

 

3

Please sign in to leave a comment.