So I’m trying to port a website (Minecraft web-based NBT editor) to a .html, and I think I’m almost there, but I’m just lost on this one step. In a JavaScript portion of the file, it referenced a file called
+new URL(./manifest.webmanifest)
which is blocked by the CORS policy with the error
index.html:1 Access to fetch at ‘file:///C:/Users/[redacted]/Downloads/Dovetail/manifest.webmanifest’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: brave, chrome, chrome-extension, chrome-untrusted, data, http, https, isolated-app.
index.html:69
And this seems to be caused by the CORS policy not allowing external files to be referenced from another file. Hence my workaround, just putting the code in the file. But I have no clue how to do this in JavaScript. This is not what I expected, as I would expect it to just work (but it never does, does it?) Thankfully, I have the data for manifest.webmanifest, so how can I write the manifest file right into the JavaScript part? (TLDR; How can I replace a URL() argument with the file’s code)
I tried writing the file URL but it still got blocked by the CORS policy. And because this is a local file, I don’t think I can bypass that
The URL() part is in this part of the code
+new URL("./manifest.webmanifest"
NOT COMPLETELY NECESSARY, JUST FOR CLARIFICATION, THIS IS NOT ANOTHER QUESTION
I do not think the manifest file is relevant as this would occur with any file. To simplify my question, the file is blocked by the computer, this is a local downloaded.html file, which the CORS policy (at least in brave) blocks the file:// protocol from accessing outside files, so the local .html file is unable to reference outside files. I have been able to bypass this by putting the code in the .html file
Example:
<script src="script.js"></script>
Becomes
<script>[code goes here]</script>
I just simply do not know how to do this in JavaScript.
I couldn’t try much as I didn’t know what to do.