Quick answer: Script error. is a placeholder, not an error message. A script loaded from another origin without CORS threw an exception, and the browser withheld the message, file, line and error object from your error handler. To get the real error, load the script with crossorigin="anonymous" and have its host send Access-Control-Allow-Origin. For scripts you cannot change, such as ad SDKs and extensions, count the event separately and wrap your own entry points in try/catch.
You wired up error reporting, shipped the build, and the top entry in the dashboard is two words long. No file, no line, no stack, thousands of occurrences. The game is throwing real exceptions with real stack traces; the browser is choosing not to show them to your page. In a browser game this usually has one fixable cause (your bundle or engine runtime is served from a CDN) and several unfixable ones (ad SDKs, portal scripts, extensions). This guide shows exactly what is muted and what is not, the two changes that unmute your own code, and how a reporter should treat the rest.
- What your handler receives
- Why the browser hides the error
- Which errors are muted
- Where it comes from in a game
- Fix: the crossorigin attribute and the CORS header
- Module scripts and dynamic import are never muted
- Wrap your own entry points
- Handle it in your error reporter
- How to verify the fix
- What Bugnet does with a muted error
- Related guides
- Frequently asked questions
What your handler receives
With the classic handler, the five arguments are:
window.onerror = function (message, source, lineno, colno, error) {
// message: "Script error."
// source: ""
// lineno: 0
// colno: 0
// error: null
};
With addEventListener("error", ...) you get an ErrorEvent carrying the same values: event.message is "Script error.", event.filename is an empty string, event.lineno and event.colno are 0 and event.error is null. Chrome, Firefox and Safari all use this exact text, including the full stop.
The developer console on the same machine still prints the real exception with its file and line. The muting applies only to what scripts on the page can observe, which is why you never see this on your own machine with DevTools open and see it constantly in reports from players.
Why the browser hides the error
A classic <script src> tag may load code from any origin, with the player’s cookies attached. If the page could read the error messages that code produces, it could learn things about a response it is not allowed to read: an error text can contain fragments of the file, or reveal whether the player is logged in to another site. The HTML specification therefore marks a script fetched from another origin without CORS as having muted errors, and when such a script throws, the browser reports the fixed string, an empty location and a null error object.
CORS is how the other origin says the page may read its response. A script fetched in CORS mode and approved by its server is not muted.
Which errors are muted
What decides it is the script in which the exception was thrown, not who called whom. These results are from a current Chrome build, with a page on one origin and a library on another without CORS:
| Situation | What your handler sees |
|---|---|
| The cross-origin script throws at top level, in its own timer or in its own callback | Script error. |
| Your code calls a function in that script, and it throws inside, uncaught | Script error. |
The same call inside your own try/catch | The real Error, with message and stack |
| The cross-origin script calls your callback, and your code throws | The real error, with your file and line |
| A promise rejects inside the cross-origin script and nobody handles it | Nothing: unhandledrejection does not fire |
Code created with eval or new Function | Treated like the script that created it |
Two rows matter most. A caught exception is never muted: muting happens when an uncaught error is reported, so the object you receive in a catch block is complete. And unhandled rejections from a muted script are dropped silently, so an async function in a CDN-hosted bundle can fail without producing even the placeholder.
Where it comes from in a game
- Your own bundle on an asset CDN or another subdomain. The HTML is on
play.mygame.exampleandgame.jsis oncdn.mygame.exampleor a storage bucket. Every error in your game is muted. This is the common case and it is completely fixable. - The engine runtime from a public CDN. Phaser, PixiJS or Three.js loaded with a plain script tag. Exceptions thrown in your callbacks are reported normally, but an exception thrown inside the engine’s code, for example because you handed it an undefined texture, is muted. Those are often your bugs.
- Portal and ad SDKs. Scripts injected by a game portal, an ad network or an analytics tag run on your page from their origin. When they throw, you get the placeholder and you cannot change how they are loaded.
- Browser extensions and in-app browsers. Extensions and the browsers embedded in social apps inject their own scripts into every page. Their failures land in your handler with nothing attached.
- Libraries pulled into a Web Worker with
importScripts. A worker’s own file must be same-origin, so its errors are real, and the page’sworker.onerrorreceives the message, file and line. A cross-origin library imported without CORS is muted inside the worker in the same way as on the page. - Unity and other engine loaders hosted on a different origin from the page. See the Unity WebGL error alert guide for how that surfaces.
One case produces no event at all: errors inside a cross-origin iframe go to that frame’s own window. If your game is embedded on a portal, your handler inside the frame works normally and the portal page sees nothing, and the reverse is also true.
Fix: the crossorigin attribute and the CORS header
Both changes are needed, and they have to ship together.
<script src="https://cdn.mygame.example/game.js" crossorigin="anonymous"></script>
and the response for game.js must include:
Access-Control-Allow-Origin: *
or your page’s exact origin plus Vary: Origin. If you add the attribute and the server does not send the header, the script does not run at all. Chrome logs Access to script at '...' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. and the game never starts, so deploy the header first.
For an S3 bucket, the CORS configuration is JSON, and Cloudflare R2 takes a policy with the same fields in the bucket settings:
[
{
"AllowedOrigins": ["https://play.mygame.example"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3600
}
]
S3 only adds the header when the request carries an Origin header, so a CDN in front of it must either forward Origin to the bucket and cache per origin, or add the header itself (in CloudFront, with a response headers policy). For nginx:
location /game/ {
add_header Access-Control-Allow-Origin "*" always;
}
Public library CDNs such as jsDelivr, cdnjs and unpkg already send the header for every file, so for an engine runtime the attribute alone is enough:
<script src="https://cdn.jsdelivr.net/npm/phaser@3.90.0/dist/phaser.min.js" crossorigin="anonymous"></script>
Scripts you add from code need the property set before src: script.crossOrigin = "anonymous". The same header and attribute pair governs images drawn to a canvas, covered in the tainted canvas guide, and the per-host setup is in the guide to CORS on a CDN.
Module scripts and dynamic import are never muted
<script type="module">, static imports and import() are always fetched in CORS mode. There is no unapproved variant, so nothing is muted: either the server sends the header and errors are reported in full, or the module fails to load. A dynamic import from a host without the header rejects with TypeError: Failed to fetch dynamically imported module in Chrome. If your build tool emits ES modules, the header is the only thing to get right.
Wrap your own entry points
For errors thrown inside scripts you cannot unmute, catch them at the boundary where your code calls in. Everything a game does starts from a small set of entry points: the frame callback, input handlers, asset callbacks and callbacks you hand to SDKs.
function guard(fn, label) {
return function guarded() {
try {
return fn.apply(this, arguments);
} catch (err) {
sendReport(err, label); // real message and stack
if (err && typeof err === "object") err.reported = true;
throw err; // keep normal behaviour
}
};
}
requestAnimationFrame(guard(frame, "frame"));
canvas.addEventListener("pointerdown", guard(onPointerDown, "input"));
adSdk.showRewarded({ onClose: guard(resumeGame, "ad close") });
Rethrowing from your own same-origin code produces a normal, unmuted error event, so mark the object and skip marked errors in the global handler to avoid filing it twice. For a direct call into third-party code, a plain try/catch around the call does the same job.
Handle it in your error reporter
A muted error filed as a bug has no stack, cannot be assigned and will be the largest entry you have. Count it, record which third-party scripts were present, and keep it out of the bug list:
var mutedCount = 0;
function thirdPartyScripts() {
return Array.prototype.filter.call(document.scripts, function (s) {
return s.src && s.type !== "module" && s.crossOrigin === null &&
new URL(s.src, location.href).origin !== location.origin;
}).map(function (s) { return s.src; });
}
window.addEventListener("error", function (event) {
if (!(event instanceof ErrorEvent)) return; // failed resource loads
var muted = event.message === "Script error." && !event.filename && !event.error;
if (muted) {
mutedCount++;
if (mutedCount === 1) console.warn("Muted error; unapproved scripts:", thirdPartyScripts());
return;
}
if (event.error && event.error.reported) return; // already sent by guard()
sendReport(event.error || new Error(event.message), "window error");
});
thirdPartyScripts() lists every classic script from another origin that lacks the crossorigin attribute. If your own CDN appears in that list, the fix above is still outstanding. If only ad and portal hosts appear, the muted count is noise from code you do not own; send the number with your session data and watch for a jump after an SDK update. The listener setup itself is covered in window.onerror vs unhandledrejection.
How to verify the fix
- Upload a one-line file next to the real bundle on the CDN:
setTimeout(function cdnThrowTest() { throw new Error("cdn throw test"); }, 0); - On a test page served from the game’s real origin, register
window.addEventListener("error", function (e) { console.log("handler saw:", e.message, e.filename, e.lineno, e.error); });and load the file with a plain script tag. The handler logsScript error., an empty file name, 0 andnull. - Add
crossorigin="anonymous"and reload. The handler now logs the message (Chrome prefixes it withUncaught Error:), the CDN URL, line 1 and anErrorobject with a stack. If the script fails to load instead, the header is missing. - Repeat in Firefox and Safari, and on the portal build: the page origin is different there, so an allowlist of origins on the CDN may not include it.
What Bugnet does with a muted error
The Bugnet Web SDK adds its own error and unhandledrejection listeners when you call Bugnet.init(), and it files what the browser gives it. It does not filter muted errors: one arrives as a report titled with the placeholder text, once per session, and identical titles from other sessions stack onto the same entry. That entry has the last 50 console lines and the user agent, and no stack, because the browser never provided one. Its occurrence count is a fair measure of how much of your error volume is invisible. Once the bundle is loaded with CORS, the same listener receives full messages and stacks. For an exception you catch at a third-party boundary, Bugnet.reportBug(title, description, { category: "other" }) files it with the real text. Setup is in the SDK docs.
Related guides
- window.onerror vs unhandledrejection: Catching Every JavaScript Error in an HTML5 Game
- 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
- Crash Reporting for Web Games on Game Portals
- How to Fix “An error occurred running the Unity content on this page” in Unity WebGL
Frequently asked questions
What does Script error. mean?
A script loaded from a different origin than the page, without CORS, threw an uncaught exception. The browser reports the fixed text Script error. with an empty file name, line 0, column 0 and no error object, so the page cannot read details about another origin’s code.
How do I get the real error instead of Script error.?
Add crossorigin=”anonymous” to the script tag and make the server that hosts the script send an Access-Control-Allow-Origin header that allows your page. Both are required. With the attribute but without the header, the script does not load at all.
Why do I only see Script error. in production and not on my machine?
In development the bundle is usually served from the same origin as the page, so nothing is muted, and the DevTools console always shows the full exception. In production the bundle often moves to a CDN or another subdomain, which makes it cross-origin.
Should I ignore Script error. in my error reports?
Do not file it as a bug, because it has no stack and nothing to act on, but do count it. A high count with your own CDN in the page means the crossorigin setup is missing. A count that comes from ad or portal scripts is noise you cannot fix.
Does try/catch get around Script error.?
Yes for exceptions that pass through your code. Muting only applies when an uncaught error is reported to the global handler. An exception caught in a try/catch block is a complete Error object with its message and stack, even when it was thrown inside a cross-origin script.
Script error. is the browser declining to tell you, not an error of its own. Ship the CORS header first and the crossorigin attribute second, and catch at every boundary where your code calls a script you do not host.