I have an HTML file that calls a script.
This script is external, which makes calls to other scripts that give me the following error:
test.min.js?v=5&lang=en&key=5454545:192 Access to XMLHttpRequest at 'file://test.com/maps/data_en.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
This problem is solved if I run the HTML on a web server, but I want a user to be able to open the HTML and run it directly locally without the need for a web server.
Is there anything I can do to avoid this error or could I just be in the chaos of accessing external scripts?
From your mistake:
XMLHttpRequest Literally means "HTTP request to get XML". Although the acronym AJAX has been outdated in terms of XML (you can request JSON or any other data type/format), what does not change is making an HTTP request.
Only an HTTP server will be able to respond to HTTP requests, so trying to load a local file via an AJAX call will always fail, even if the Javascript file does not have the CORS problem.
I leave you the solution for chrome, you must execute the following command in the console and it will execute a browser window disabling the CORS lock.
Source: https://alfilatov.com/posts/run-chrome-without-cors/