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

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.

BrowserMessage
Chrome, EdgeAccess to script at 'file:///...' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: ...
FirefoxCross-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:///...”.
SafariOrigin 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:

FeatureFrom file://
Classic <script src>Works
<img>, <audio> and <video> elements, for display and playbackWorks
localStorageWorks
<script type="module">, import and import()Blocked with the error above
fetch and XMLHttpRequest for JSON, atlases, audio buffers, .wasm and data packsBlocked 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 textureFails. Chrome throws SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The image element contains cross-origin data, and may not be loaded.
Service worker registrationFails

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.

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:

Three things to know about a local server:

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:

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:

  1. 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.
  2. 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.
  3. 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 includes data, and classic scripts are not subject to the block. This suits small games.
  4. 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

  1. The address bar shows http://localhost:8000/, not a path starting with file:///.
  2. window.origin in the console prints "http://localhost:8000" instead of "null".
  3. The console has no CORS lines, and every row in the Network tab has status 200.
  4. 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.

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.