Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS Policy Error When Loading Local JS File in HTML #33

Open
ZacharyZcR opened this issue Jun 6, 2024 · 0 comments
Open

CORS Policy Error When Loading Local JS File in HTML #33

ZacharyZcR opened this issue Jun 6, 2024 · 0 comments

Comments

@ZacharyZcR
Copy link

ZacharyZcR commented Jun 6, 2024

Description

During local development, when trying to load a JavaScript file from an HTML file, I encountered a CORS policy error. The error message is as follows:

Access to script at 'file:///C:/Users/Administrator/Desktop/zodiac-dev/zodiac-dev/main.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

This issue prevents the JavaScript file from loading properly, which affects the functionality of the page.

Steps to Reproduce

Place the HTML file and JavaScript file in a local folder.
Open the HTML file by double-clicking it or directly opening the file path file:///C:/Users/Administrator/Desktop/zodiac-dev/zodiac-dev/zodiac.html in the browser.
Observe the browser console to find the aforementioned CORS error.

Expected Behavior

The HTML file should be able to load and execute the local JavaScript file without interference from CORS policies.

Actual Behavior

The browser blocks the loading of the JavaScript file, throwing a CORS policy error.

Possible Solutions

It is recommended to set up a local development server, such as using Python's HTTP server module, or host the files through a web server software like Apache or Nginx. This can prevent CORS issues associated with opening files directly from the file system.

Environment Information

Operating System: Windows 10
Browser: Google Chrome Version 125.0.6422.142
File Path: C:/Users/Administrator/Desktop/zodiac-dev/zodiac-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant