Quick answer: The alert is shown by Unity’s loader script for any uncaught error that comes out of the build. The useful part is the line after “The error was:”. Most of those lines are WebAssembly traps caused by a C# exception the build was not set up to catch. Rebuild with Enable Exceptions set to Full With Stacktrace and Debug Symbols on, reproduce it, and the trap becomes a named exception with a C# stack.
Players send you a screenshot of a browser dialog that says an error occurred and to check the JavaScript console, which they will not do. The dialog is generic. It is the same box for a null reference in your inventory code, a plugin that passed a bad pointer, a phone that ran out of memory and a CDN that served two different builds at once. The part that tells them apart is the last line. This guide is a decoder for that line, a method for turning it into a C# stack trace, and a way to replace the alert with something better for players and for you.
- The exact message
- Decoding the line after “The error was”
- Why a C# bug shows up as a WebAssembly trap
- How to get a readable error
- When the alert appears while the game is loading
- Replace the alert with your own handling
- How to confirm the fix
- What Bugnet can capture from a WebGL build
- Related guides
- Frequently asked questions
The exact message
An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
RuntimeError: memory access out of bounds
The box is a plain browser alert() raised by the loader script Unity ships with every WebGL build: Build/<name>.loader.js in Unity 2020 and later, UnityLoader.js before that. The loader listens for uncaught errors and unhandled promise rejections, and when one comes from the build it shows this text followed by the error. The first two sentences never change. Everything you need is after “The error was:”.
For a few errors the loader substitutes its own wording, so you may see one of these instead:
An exception has occurred, but exception handling has been disabled in this build. If you are the developer of this content, enable exceptions in your project WebGL player settings to be able to catch the exception or see the stack trace.
Out of memory. If you are the developer of this content, try allocating more memory to your WebGL build in the WebGL player settings.
The browser could not allocate enough memory for the WebGL content. If you are the developer of this content, try allocating less memory to your WebGL build in the WebGL player settings.
Once the alert has appeared, the game is finished for that page load. The exception unwound through the main loop, and the loader shows the alert only once.
Decoding the line after “The error was”
The wording below is Chrome’s. Firefox and Safari describe the same traps differently: for the first row Firefox prints “index out of bounds” and Safari “Out of bounds memory access”, and for the third Firefox prints “unreachable executed”.
| The error was | What happened | Usual cause in a Unity game |
|---|---|---|
RuntimeError: memory access out of bounds | A read or write outside the WebAssembly memory | A C# null or bad index with exception checks off, a .jslib plugin writing past a buffer, or memory exhaustion. See the dedicated guide. |
RuntimeError: null function or function signature mismatch | An indirect call through an empty or wrongly typed function slot | A method call on a null object with checks off, or a C# callback invoked from JavaScript with the wrong signature |
RuntimeError: unreachable | Code hit an instruction that means “this must never run” | The runtime aborted on purpose: an exception was thrown in a build that cannot throw, or an internal assert failed |
RuntimeError: table index is out of bounds | An indirect call through an index beyond the function table | A corrupted or stale function pointer, usually a delegate handed to JavaScript and called after it was freed |
RuntimeError: divide by zero | Integer division by zero | A C# integer division that would be a DivideByZeroException with checks on |
abort(...) or Aborted(...) | The Emscripten runtime stopped and gave a reason in the brackets | Read the reason: an out-of-memory message, a failed WebAssembly compile, or a missing native function |
| A C# exception name and message | A managed exception reached the top of the stack | An ordinary bug in your scripts, already readable |
Script error. | The browser hid the details of a cross-origin script error | Build files served from another origin without CORS. See what “Script error.” means. |
Rows one, two, three and five are frequently the same bug wearing different clothes. Which trap you get depends on what the bad value happened to be and what the code did with it next.
Why a C# bug shows up as a WebAssembly trap
In the editor and in desktop builds, dereferencing null throws a NullReferenceException, Unity logs it, and the game continues with the next frame. A WebGL build only does that if you ask for it. Player Settings > Publishing Settings > Enable Exceptions controls how much checking IL2CPP compiles in:
| Setting | What is caught | Cost |
|---|---|---|
| None | Nothing. Any exception ends the game. | Smallest and fastest |
| Explicitly Thrown Exceptions Only (the default) | Exceptions raised by a throw statement. Null references and out-of-range array accesses are not checked. | Small |
| Full Without Stacktrace | Thrown exceptions, null references and out-of-range array accesses | Larger and slower |
| Full With Stacktrace | The same, with a managed stack trace attached | Largest and slowest; for debugging |
With the default setting, a null reference in your code is not detected. The compiled code reads through the null pointer anyway. In WebAssembly, address zero is ordinary readable memory, so the read succeeds and returns garbage. If the next step is a virtual method call, the garbage is used as a function slot and you get “null function or function signature mismatch”. If it is used as an address, you get “memory access out of bounds”. The bug is one missing null check; the message depends on luck.
That is also why the same build can run for minutes before failing, and why the error text may change between two runs of the same bug.
How to get a readable error
- Read the console, not the alert. Press F12 and copy the whole error from the Console tab. The alert cuts the stack short.
- Make a debugging build. Turn on Development Build in the build window, set Enable Exceptions to Full With Stacktrace, and set Debug Symbols to Embedded (a single checkbox in Unity 2021 and earlier). Symbols turn frames such as
wasm-function[48213]into function names. - Reproduce it. The trap is now a managed exception. The console shows its type, message and C# call stack, and in many cases the game survives the frame the way it would on desktop.
- Fix the script, then rebuild for release with your normal settings.
NullReferenceException: Object reference not set to an instance of an object.
at InventoryUI.Refresh () [0x00000] in <00000000000000000000000000000000>:0
at InventoryUI.OnEnable () [0x00000] in <00000000000000000000000000000000>:0
If the error survives with full exceptions on and still reads as a raw trap, the fault is not in managed code. Look at .jslib plugins and native libraries next, and at memory. A callback is the classic plugin case: the static C# method passed to JavaScript needs the [MonoPInvokeCallback] attribute, and the JavaScript side has to call it with exactly the parameter types the C# delegate declares.
Some teams ship with Full Without Stacktrace so that a stray null reference costs one frame instead of the session. That is a legitimate trade if you measure the size and frame-time cost on your slowest target first.
When the alert appears while the game is loading
An error before the first frame is rarely in your scripts. Check these in order:
- Files from two different builds. The browser or a CDN cached the old
.wasmor.dataand fetched a new.framework.js. The pieces do not match and the build fails with a compile, link or signature error. Turn on Publishing Settings > Name Files As Hashes so each build has unique file names, and purge the CDN after a deploy. - Compressed files served with the wrong headers. See the “Unable to parse Build” guide.
- Opened from disk. A build opened as a
file://page cannot fetch its WebAssembly. Serve it over HTTP, or use Build And Run. - Not enough memory to start. “The browser could not allocate enough memory” at load means the initial memory request was refused, which happens mostly on phones. Lower the initial memory size in the WebGL memory settings and reduce what the first scene loads. The out of memory guide covers the settings.
Replace the alert with your own handling
A blocking browser dialog that tells players to open a JavaScript console is a poor last impression, and it gives you nothing. The loader lets the page take over. In the 2020 to Unity 6 loaders, it looks for an errorHandler function on the configuration object passed to createUnityInstance, calls it with the message, file name and line number, and skips its own alert when the function returns true. Search your Build/*.loader.js for errorHandler to confirm your version has the hook. Then add it to the config in your WebGL template’s index.html:
var config = {
dataUrl: buildUrl + "/MyGame.data",
frameworkUrl: buildUrl + "/MyGame.framework.js",
codeUrl: buildUrl + "/MyGame.wasm",
companyName: "Studio",
productName: "My Game",
productVersion: "1.0.3",
showBanner: unityShowBanner,
errorHandler: function (message, filename, lineno) {
showCrashScreen(); // your own overlay with a Reload button
reportFatalError(message, filename, lineno);
return true; // handled: the loader shows no alert
},
};
Keep the overlay simple: say the game stopped, offer a reload button, and say whether progress was saved. Send yourself the message, the browser’s user agent and the build version. Put the handler in a custom WebGL template so a rebuild does not overwrite it.
One difference between loader generations is worth knowing. Loaders from Unity 2020 onward only react to errors whose stack trace points into the build’s own files. The older UnityLoader.js reacted to any uncaught error on the page, so an advert or a portal script throwing could produce the Unity alert for a game that was running fine.
How to confirm the fix
Reproduce the original steps in the release build, with release settings, in the browser the report came from. Then repeat in Chrome, Firefox and Safari, and on a phone if you support mobile, because memory limits and trap wording differ. Keep the console open and confirm it stays free of errors through the scene that used to fail. If you changed Enable Exceptions for release, compare build size and frame time before and after. For a loading failure, test from a private window so nothing is cached, and again after a second deploy to prove the hashed file names are doing their job.
What Bugnet can capture from a WebGL build
The Bugnet Unity SDK is ordinary C#, so it runs in WebGL builds. It files every error and exception Unity logs, with the stack trace and recent log lines, once per distinct message per session. That covers managed exceptions, which is one more reason to consider a Full exceptions setting: a null reference that is caught becomes a report you can read. A raw WebAssembly trap is different. It stops the runtime before any C# can run, so the Unity SDK cannot report it. The trap does surface on the page as an uncaught error, which is what the Web SDK listens for when its script is added to the template page. It files the message with the stack, recent console lines and the user agent. Setup for both is in the SDK docs.
Related guides
- How to Fix “RuntimeError: memory access out of bounds” in Unity WebGL
- How to Fix a Unity WebGL Build Running Out of Memory
- How to Fix “Unable to parse Build/WebGL.framework.js.gz” in a Unity WebGL Build
- Crash Reporting for Unity WebGL Builds
- What Does “Script error.” Mean in a Web Game? (and How to Get the Real Error)
Frequently asked questions
What does “An error occurred running the Unity content on this page” mean?
It is a generic alert from Unity’s WebGL loader script, shown when an uncaught error comes out of the build. It is not the error itself. The real error is the line after “The error was:”, and the full stack is in the browser’s JavaScript console.
Why does my Unity WebGL build show RuntimeError instead of a C# exception?
With the default Enable Exceptions setting, IL2CPP does not check for null references or out-of-range array accesses in WebGL builds. The bad access runs anyway and ends as a WebAssembly trap. Setting Enable Exceptions to a Full option turns it back into a managed exception.
How do I see the C# stack trace for a Unity WebGL error?
Build with Development Build on, Enable Exceptions set to Full With Stacktrace and Debug Symbols enabled, then reproduce the error with the browser console open. The console shows the exception type, message and C# call stack. Switch back to your release settings afterwards.
Can I hide or replace the Unity WebGL error alert?
Yes. Add an errorHandler function to the configuration object passed to createUnityInstance in your WebGL template. The loader calls it with the message, file name and line number, and shows no alert if it returns true. Use it to show your own reload screen and to report the error.
Why does the error only happen for some players?
Common reasons are a cached mix of files from two builds, a browser or phone with less memory, and a code path only some players reach. Name Files As Hashes fixes the first. For the others, collect the browser, device and exact error line from affected players.
The alert is the same for every failure, so never debug from it. Get the line after “The error was”, rebuild with full exceptions and symbols, and you are reading a C# stack trace instead of a wasm trap.