Why the details are hidden#
A page can load a script from any origin. If the browser passed that script's error messages to the page, a page could probe scripts from other sites and learn private information from their errors. The HTML standard therefore gives a classic script fetched without CORS muted errors: error events from it carry no message, file or position. HTML standard: muted errors ยท MDN: crossorigin on scripts
Reproduced in Chromium#
A page on http://localhost:8101 loaded the same failing script twice from http://127.0.0.1:8102: once with a plain <script src>, once with crossorigin="anonymous" while the server sent Access-Control-Allow-Origin: http://localhost:8101. The page logged each error event.
plain <script>:
message="Script error." filename="" lineno=0 error=null
crossorigin + Access-Control-Allow-Origin:
message="Uncaught TypeError: Cannot read properties of undefined (reading 'length')"
filename="http://127.0.0.1:8102/widget.js?cors=1" lineno=1
error=TypeError: Cannot read properties of undefined (reading 'length')
The DevTools Console showed the full TypeError in both cases. DevTools is not subject to muting; only the page's own error handlers are. That difference is the quickest way to recover the message for one user: reproduce with DevTools open and copy the Console text.
Two causes behind Script error.#
| Cause A: your own script, served from another origin | Cause B: a third-party script you do not control | |
|---|---|---|
| Examples | Your bundle on a CDN or static host such as static.example.test | A chat widget, analytics tag or payment script |
| Fix | Send Access-Control-Allow-Origin from the asset host and add crossorigin="anonymous" to the tag | Ask the vendor; you can only add crossorigin if their server sends CORS headers |
| What to report | The asset host and the missing header | The vendor, the script URL and the Console text from a reproduction |
The deciding observation is the script's origin. Find every <script src> whose origin differs from the page's, and check each one's response headers in the Network panel for Access-Control-Allow-Origin. The script whose error you are chasing is usually the one that loads just before the time of the error, or the one named in the Console's stack in a reproduction.
Add crossorigin only with the header#
Adding crossorigin="anonymous" to a script tag changes how the browser fetches it: the request uses CORS. If the server does not answer with an Access-Control-Allow-Origin that matches the page, the browser refuses to run the script. Turn on the header first, check it in the Network panel, then add the attribute. MDN: CORS settings attributes
Module scripts, loaded with type="module", always use CORS for cross-origin fetches, so their errors are not muted.
Worked example: an error spike nobody can read#
This example is fictional. An error tracker shows 3,000 Script error. events a day from the checkout page, with no stack. The team cannot tell whether checkout is broken.
The checkout page loaded three cross-origin scripts: the app bundle from static.shop.test, a payment script and a chat widget. Only the bundle's host was the team's own. Its responses had no Access-Control-Allow-Origin. After the asset host sent the header and the tag gained crossorigin="anonymous", the same events arrived as TypeError: Cannot read properties of null (reading 'addEventListener') from checkout-7d1e.js, line 1, which the source map guide then mapped to a missing element check.
The report before the change said: Script error. events come from a cross-origin script loaded without CORS. Our bundle on static.shop.test is one of three candidates; it lacks Access-Control-Allow-Origin. Turning on CORS for that host will show whether the errors are ours. That was enough for the receiver to act without guessing.
What to put in the report#
- The page's origin and the origin of each script it loads.
- Which scripts carry
crossoriginand which responses carryAccess-Control-Allow-Origin. - The Console text from a reproduction with DevTools open, which is not muted.
- The time and page of the tracked events.
Questions#
Does crossorigin send cookies to the script host?
With crossorigin="anonymous", the browser sends credentials only to a same-origin host. crossorigin="use-credentials" sends them cross-origin and requires the host to allow credentials. Static assets rarely need credentials.
Can a browser extension cause Script error.?
Yes. Errors from extension scripts injected into the page can surface in the page's handlers. If the events come from a small set of users, compare them with the incognito test.
Why do I see Script error. only in production?
Development servers usually serve scripts from the page's own origin. Production often moves them to a CDN on another host, which is when muting starts.
Return to the method for browser bug reports for the other symptoms in this collection.