Quick answer: You opened index.html by double-clicking it, so the page runs from a file:// address. Browsers give such a page the origin null and refuse to let it load ES modules or read other files with fetch, because those requests need CORS and CORS only exists over HTTP. Nothing is wrong with your code. Serve the folder from a local web server (for example python3 -m http.server 8000) and open http://localhost:8000/ instead.
The page opens, the canvas is empty, and the console says a file sitting next to index.html on your own disk was blocked by CORS policy. It reads like a server configuration problem, and there is no server. That is the problem. This guide shows the message in each browser, exactly which features stop working on a file:// page, the commands that serve a game folder over HTTP, why browser flags are a poor substitute, and what to do about players who download your HTML build as a zip.
- The exact error
- Why a file on your own disk is “cross-origin”
- What works and what breaks on a file:// page
- How engine exports report it
- Fix: serve the folder over HTTP
- Why browser flags are a poor fix
- Players who download an HTML build as a zip
- Confirm the fix
- What Bugnet can and cannot report here
- Related guides
- Frequently asked questions
The exact error
Chrome prints this for a module script, followed by a failed-load line for the same file:
Access to script at 'file:///C:/game/src/main.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome, chrome-extension, chrome-untrusted, data, http, https, isolated-app.
Failed to load resource: net::ERR_FAILED
The list of schemes at the end differs between Chrome versions and between Chrome and Edge. Older versions print a shorter one (http, data, chrome, chrome-extension, https). The parts to read are file:/// and origin 'null'. The same sentence appears for other kinds of request, with the first words changed: Access to fetch at, Access to XMLHttpRequest at and Access to image at.
| Browser | Message |
|---|---|
| Chrome, Edge | Access to script at 'file:///...' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: ... |
| Firefox | Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///.... (Reason: CORS request not http). For modules it adds Module source URI is not allowed in this document: “file:///...”. |
| Safari | Origin null is not allowed by Access-Control-Allow-Origin. Status code: 0 for module scripts, and Cross origin requests are only supported for HTTP. with Fetch API cannot load file:///... due to access control checks. for fetch |
Your code sees only a generic failure: fetch rejects with TypeError: Failed to fetch in Chrome, NetworkError when attempting to fetch resource. in Firefox and Load failed in Safari.
Why a file on your own disk is “cross-origin”
An origin is a scheme, a host and a port, such as https://mygame.example. A file:// address has no host, so browsers cannot say which files belong together. They take the strict position: each page opened from disk gets a unique, opaque origin, which prints as null. You can see it by typing window.origin in the console of such a page.
Under that rule every other file is cross-origin, including the one in the same folder. A cross-origin read is allowed only when the other side grants it with CORS response headers. A file has no response headers, so the grant can never arrive, and Chrome says so directly: cross-origin requests are only supported for a list of schemes that does not include file.
The rule protects you. Without it, any HTML file you downloaded and opened could read other files on your disk and send them elsewhere.
What works and what breaks on a file:// page
Not everything needs a readable origin, which is why a small game can work from disk for weeks and then stop the day you add modules or a JSON level. These results are from current Chrome, Firefox and WebKit builds:
| Feature | From file:// |
|---|---|
Classic <script src> | Works |
<img>, <audio> and <video> elements, for display and playback | Works |
localStorage | Works |
<script type="module">, import and import() | Blocked with the error above |
fetch and XMLHttpRequest for JSON, atlases, audio buffers, .wasm and data packs | Blocked with the error above |
WebAssembly.instantiateStreaming(fetch(...)) | Fails, because the fetch fails |
new Worker("worker.js") | Fails. Chrome throws SecurityError: Failed to construct 'Worker': Script at 'file:///...' cannot be accessed from origin 'null'. |
Reading pixels back from a canvas after drawing a local image (getImageData, toDataURL) | Fails with a SecurityError: the canvas is tainted |
| Uploading a local image as a WebGL texture | Fails. Chrome throws SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The image element contains cross-origin data, and may not be loaded. |
| Service worker registration | Fails |
Module scripts are in the blocked group because the browser always fetches them with CORS, with no exemption for local files. Most engine loaders use fetch or XMLHttpRequest for every asset, images included, so with an engine nearly everything lands in the blocked rows. The canvas and texture rows are the same rule that produces tainted canvases on the web, explained in the tainted canvas guide.
How engine exports report it
Engines that expect this mistake put their own message on the page.
- Unity WebGL. Current loaders show a banner that names the file and the cause:
Failed to download file Build/MyGame.data. Loading web pages via a file:// URL without a web server is not supported by this browser. Please use a local development web server to host Unity content, or use the Unity Build and Run option.Older Unity versions showed an alert instead:It seems your browser does not support running Unity WebGL content from file:// urls. Please upload it to an http server, or try a different browser. - Godot 4 web exports. The export shell loads the engine’s
.wasmand.pckfiles withfetch, so from disk the load fails and the console shows the CORS message. An export with thread support stops earlier withThe following features required to run Godot projects on the Web are missing:followed byCross-Origin IsolationandSharedArrayBuffer, since a page opened from disk is never cross-origin isolated. That message has its own guide: Cross Origin Isolation and SharedArrayBuffer in a Godot web export. - Phaser, PixiJS, Three.js. No special message. The first asset request fails with
Access to XMLHttpRequest at 'file:///...'orAccess to fetch at 'file:///...'. - Bundler output. A production build from Vite or a similar tool loads its bundle as a module, so opening
dist/index.htmldirectly fails with this error, or withnet::ERR_FILE_NOT_FOUNDwhen the build uses paths that start with/.
Fix: serve the folder over HTTP
Any static file server will do. Start it in the folder that contains index.html and open the address it prints. Nothing about the game needs to change.
With Python 3, which most Linux systems and many Macs already have:
cd path/to/game
python3 -m http.server 8000
On Windows with Python installed, the launcher is py:
cd C:\game
py -m http.server 8000
Then open http://localhost:8000/. With Node.js, either of these works without installing anything permanently:
npx serve .
npx http-server . -p 8000 -c-1
serve prints the address it chose. The -c-1 option tells http-server not to cache, which saves you from testing an old file after an edit. Other routes to the same result:
- A bundler project.
npx vitestarts the dev server, andnpx vite previewserves the production build fromdist. - Visual Studio Code. Install the Live Server extension, right-click
index.htmland choose Open with Live Server. - Unity. Use File > Build And Run, which hosts the build on a local server and opens it.
- Godot. Use the editor’s run-in-browser button for the Web export preset, which starts a local server for you.
Three things to know about a local server:
http://localhostcounts as a secure context, so features that otherwise need HTTPS (service workers, for example) work there.- Python’s server listens on every network interface by default, which lets you open the game on a phone at your computer’s LAN address. Add
--bind 127.0.0.1to keep it private to your machine. - A basic static server does not send the cross-origin isolation headers that threaded WebAssembly builds need. If the game loads but reports
SharedArrayBuffermissing, that is a separate header problem, not this one.
Why browser flags are a poor fix
You will find advice to start Chrome with --allow-file-access-from-files or to set security.fileuri.strict_origin_policy to false in Firefox’s about:config. Both work in the narrow sense: in a test with current builds, modules, fetch, workers and canvas reads all succeeded from disk afterwards. The reasons not to rely on them:
- The setting applies to every local HTML file that browser profile opens, not only your game. It removes the protection described above for anything you download.
- The Chrome flag is read at startup. If any Chrome window is already open, the new one joins the running process and the flag is ignored, which leads to the impression that it “stopped working”.
- It is still not the environment your players get. Service workers still fail, paths starting with
/still point at the disk root, and you learn nothing about case-sensitive file names, MIME types or caching, all of which a server shows you before release. - Players do not have the flag, so a build that only runs with it is not shippable.
Players who download an HTML build as a zip
If you distribute the web build as a download, every player who double-clicks index.html gets this error and a blank page. Choose one of these before release:
- Host the web build and link to it. An embedded build on a portal or a static host is served over HTTPS, and the problem does not exist there.
- Ship a desktop wrapper for downloads. Tools such as Electron, Tauri or NW.js package the same HTML and JavaScript as a desktop application, which is the usual way to ship an HTML5 game as a download.
- Make a build that needs no requests. Bundle the code into one classic script (an IIFE build, not ES modules) and embed assets as
data:URLs. The scheme list in Chrome’s message includesdata, and classic scripts are not subject to the block. This suits small games. - Tell the player what happened. A classic inline script still runs from disk, so the page can detect the situation and explain it:
<script>
if (location.protocol === "file:") {
document.body.textContent =
"This game cannot run when opened directly from a folder. " +
"Play it online at mygame.example/play, or see README.txt " +
"for how to start it with a local web server.";
}
</script>
Place that script inside <body>, before the tag that loads the game.
Confirm the fix
- The address bar shows
http://localhost:8000/, not a path starting withfile:///. window.originin the console prints"http://localhost:8000"instead of"null".- The console has no CORS lines, and every row in the Network tab has status 200.
- If assets now return 404, the server is running in the wrong folder or a path is wrong. That is a different problem with a different guide: a web game that returns 404s after deploy.
What Bugnet can and cannot report here
For you, this is a development-time error that never reaches a player once the game is hosted. For a player who opens a downloaded build from disk, the game does not start, and a game that never starts cannot report itself. The blocked module script raises no error event that the Bugnet Web SDK listens for, so even an SDK loaded with a classic script tag has nothing to file.
What Bugnet offers for a launch failure like this is the project’s public tracker. A known-issue entry titled with the exact console message, saying that the build must be played from the hosted link or started through a local server, is what a player finds when they search for the error. Once the game is served over HTTP, automatic capture of uncaught errors and the in-game report form work as usual.
Related guides
- How to Fix Game Assets Blocked by CORS When Served From a CDN
- How to Fix “Tainted canvases may not be exported” in a Web Game
- How to Fix “TypeError: Failed to fetch” in a Web Game
- How to Fix “Cross Origin Isolation” and “SharedArrayBuffer” Missing Errors in a Godot Web Export
- How to Fix a Web Game That Works Locally but Returns 404s on GitHub Pages or itch.io
Frequently asked questions
What does blocked by CORS policy from origin null mean?
The page was opened from a file:// address, usually by double-clicking index.html. Browsers give such pages an opaque origin that prints as null and treat every other file as cross-origin, and a cross-origin read needs CORS headers that a file on disk cannot send.
How do I fix Access to script at file:// blocked by CORS policy?
Serve the folder from a local web server and open it through http://localhost. Run python3 -m http.server 8000 or npx serve in the folder that contains index.html, then open the address in the browser. No change to the game code is needed.
Why did my game work from a file before and stop now?
Classic script tags and plain image and audio elements work from disk. ES modules, fetch, XMLHttpRequest, workers, WebAssembly loading, WebGL textures and reading pixels back from a canvas do not, so the game breaks when you add the first of those.
Can I use --allow-file-access-from-files instead of a server?
It removes the block in Chrome, but for every local HTML file opened with that profile, and only if Chrome was fully closed before starting it with the flag. Your players do not have the flag, and you lose the checks a server gives you for paths, case and caching.
Why does my Unity WebGL or Godot web build not run when I open index.html?
Both engines load their data and WebAssembly files with fetch, which is blocked on a file:// page. Unity shows a message that loading via a file:// URL without a web server is not supported, and Godot fails while loading. Use Unity's Build And Run, Godot's run in browser button, or any local web server.
A page opened from disk has no origin, so nothing is wrong with your CORS setup or your code. Develop and test through http://localhost from the first day, and never ship a build that players are expected to double-click.