Fixed: Access to script at 'file:///…' from origin 'null' has been blocked by CORS policy
I opened a small web page straight from the disk, and its script didn't run. Chrome's console said Access to script at 'file:///…' from origin 'null' has been blocked by CORS policy. Nothing was wrong with the script: the browser won't make that kind of request for a file on the disk, and a one-line local web server fixes it.
What I Was Doing
The page loads its script with a Subresource Integrity hash, so the browser checks the file before it runs it. That needs two attributes on the script tag, integrity and crossorigin:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SRI demo</title>
</head>
<body>
<p id="greeting">The script hasn't run.</p>
<script src="greeting.js"
integrity="sha384-IVgd0lDQl4XfieCfj3m+tlhOPZteADgAx/Sn3z5gsb8AZaPQR+Gf/lI6vqmG51R0"
crossorigin="anonymous"></script>
</body>
</html>
The script replaces the paragraph's text:
document.getElementById("greeting").textContent = "Hello from the new greeting.js!";
Both files were in one folder, and the hash matched greeting.js. I opened index.html in Chrome straight from the disk, as a file:/// address.
What I Expected
Hello from the new greeting.js!
What I Got
The page still said The script hasn't run.:

And the console, which F12 opens in Chrome and Edge, had two errors:
Access to script at 'file:///Users/you/sri-demo/greeting.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome, chrome-experimental-site-token-provider, chrome-extension, chrome-untrusted, data, http, https, isolated-app.
Failed to load resource: net::ERR_FAILED
What I Checked
Whether the hash was the problem. No: when a hash doesn't match, Chrome says Failed to find a valid digest in the 'integrity' attribute. This was a different error, about CORS, before any hash was checked.
What crossorigin does. It makes the browser fetch the file with CORS, the rules browsers use to decide whether one site may read another site's files. Subresource Integrity needs it: MDN's Subresource Integrity guide says you must include the crossorigin attribute in your markup when you use integrity.
What the error says about file:///. It lists the schemes CORS requests can use, and file isn't one of them. MDN's page on this error, Reason: CORS request not HTTP, says: CORS requests may only use the HTTP or HTTPS URL scheme, but the URL specified by the request is of a different type. This often occurs if the URL specifies a local file, using the file:/// scheme.
What origin 'null' means. The same page explains it: Many browsers, including Firefox and Chrome, now treat all local files as having opaque origins (by default). As a result, loading a local file with included local resources will now result in CORS errors. An opaque origin shows up as null.
Why It Happens
The crossorigin attribute turns the script request into a CORS request. Browsers only make CORS requests over http and https, and a page opened from the disk has no real origin of its own, only null. So Chrome stopped the request before it reached the file, and the script never loaded.
The page itself was fine. It was built to be served by a web server, as every page on the web is.
The Fix
Serve the folder with a local web server, and open the page through it. Python has one built in. In the folder with index.html:
- macOS / Linux
- Windows (PowerShell)
python3 -m http.server 8081
py -m http.server 8081
Serving HTTP on :: port 8081 (http://[::]:8081/) ...
Then open http://localhost:8081/ in the browser. MDN gives the same advice: Developers who need to perform local testing should now set up a local server. The server keeps running until you press Ctrl+C in its terminal.
The page itself needs no change: the same index.html, with integrity and crossorigin still on its script tag, runs its script as soon as it's served.
After the Fix
Opened from http://localhost:8081/, the page ran its script:

The console had no CORS error, and the server's terminal showed the page and the script being requested:
::1 - - [03/Dec/2026 09:05:09] "GET / HTTP/1.1" 200 -
::1 - - [03/Dec/2026 09:05:09] "GET /greeting.js HTTP/1.1" 200 -
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Opening an HTML file from the disk when its script tags use crossorigin | The browser blocks those scripts with a CORS error | Open the page through a local web server |
Opening http://localhost:8081/ while the server isn't running | The browser can't connect | Start the server in the page's folder first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
from origin 'null' has been blocked by CORS policy | The page was opened from a file:/// address | Serve it, and use http://localhost:8081/ |
OSError: [Errno 48] Address already in use when you start the server on macOS | Another program is already using port 8081 | Start it on another port, such as python3 -m http.server 8082, and open http://localhost:8082/ |
| The browser shows Directory listing for / instead of the page | The server was started in another folder | Stop it with Ctrl+C and start it in the folder that holds index.html |
FAQ
Does this happen in every browser?
MDN's page says many browsers, including Firefox and Chrome, treat local files this way. The error in this guide is Chrome's.
Can I use another web server?
Yes. Any server that serves the folder over http://localhost works, such as the one in your editor or your project's own development server. Python's is used here because it needs nothing extra.
Conclusion
Access to script at 'file:///…' from origin 'null' has been blocked by CORS policy means a page opened from the disk asked for a script with CORS, which browsers only do over http and https. The page is fine. Serve its folder with python3 -m http.server 8081 and open http://localhost:8081/.
Additional Resources
- Reason: CORS request not HTTP, on MDN.
- Subresource Integrity, on MDN.
- http.server, in the Python documentation.
