On this page
What this issue is
When JavaScript fails, the browser fires an error event with a message, file name and line number. If the failing script was loaded from a different origin (a different domain, such as a tag manager, chat widget or CDN) and was not loaded in a CORS-enabled way, the browser withholds all of that. Your error logger only receives the text Script error., with line 0 and no file.
window.addEventListener('error', function (e) {
console.log(e.message); // "Script error."
console.log(e.filename); // ""
console.log(e.lineno); // 0
console.log(e.error); // null
});Why it costs you leads or sales
- Page loadsThird-party script requested from another domain
- Script throwsBrowser reports only 'Script error.'
- Widget or tag failsForm, chat or tracking does not run
- Lead or conversionNot submitted or not recorded
The error report is empty, so the break goes unnoticed until leads drop.
How to check if your site has it
Check your error logger
Search your error monitoring tool or logs for the exact message 'Script error.' with line 0 or an empty file name.
List your third-party scripts
Open the page, then DevTools > Network > filter JS. Note every script whose domain differs from your own.
Open the Console
Load the page and walk through the form or checkout. In the Console, errors from other origins usually show the real message, even when your logger sees only 'Script error.'
Check the headers
Click a third-party script in the Network tab and look for an Access-Control-Allow-Origin response header.
How to fix it
<script src="https://cdn.example.com/widget.js" crossorigin="anonymous"></script>Add crossorigin to external scripts
Add crossorigin="anonymous" to each script tag loaded from another domain that sends CORS headers.
Serve your own scripts with CORS
If your scripts sit on a separate CDN or subdomain, send Access-Control-Allow-Origin for your site origin (or *) from that host.
Log the right fields
In your error handler, record e.message, e.filename, e.lineno and e.error?.stack so detail appears once CORS is in place.
Find the source
Use DevTools to identify which plugin or theme loads the third-party script.
Add the attribute for scripts you control
For scripts your theme or plugin enqueues from a CDN, add the attribute with the script_loader_tag filter in a child theme or small plugin.
Update or replace the plugin
If a vendor script is failing, update the plugin or contact its support with the console error.
Use Preview mode
Open Tag Assistant preview and look for tags that show a failure. Custom HTML tags that load external scripts are the usual source.
Add crossorigin in Custom HTML tags
If a Custom HTML tag injects a script, set script.crossOrigin = 'anonymous' before appending it, provided the host allows CORS.
Isolate the app
Most third-party scripts come from apps. Disable apps one by one on a duplicate theme and watch the console.
Edit your own script tags
For scripts you added in theme.liquid, add crossorigin="anonymous" only when the host sends CORS headers. Report app errors to the app developer.
add_filter('script_loader_tag', function ($tag, $handle, $src) {
if ($handle === 'my-cdn-script') {
return str_replace('<script ', '<script crossorigin="anonymous" ', $tag);
}
return $tag;
}, 10, 3);location ~* \.js$ {
add_header Access-Control-Allow-Origin "https://www.example.com";
}How to confirm it's fixed
- Trigger the error again and see a real message, file name and line number in your logger
- The third-party script still loads (status 200 in the Network tab)
- The Console shows no new CORS errors
- The form, chat or tracking tag that depends on the script still works
- Test the page in at least two browsers
Before
- Message: Script error.
- File: empty
- Line: 0
- No stack trace
After
- Message: the real error text
- File: the script URL
- Line and column filled in
- Stack trace available
How to prevent it happening again
- Add crossorigin="anonymous" to every external script whose host supports CORS
- Keep a list of third-party scripts and who owns each one
- Serve your own assets from a CDN with CORS headers set
- Capture e.error and its stack, not only e.message
- Review the console after adding any new tag, app or plugin
How FunnelGuard handles this
Questions people ask
What does 'Script error.' mean in JavaScript?
It means a script from another origin threw an error and the browser hid the details for security. You get the text 'Script error.' with no file name, line number or stack trace.
Why is my error log showing 'Script error.' with line 0?
The failing script was loaded from a different domain without CORS enabled. The browser strips the file and line to prevent leaking information across origins, so your handler sees line 0 and an empty file name.
How do I fix 'Script error.' on a third-party script?
Add crossorigin="anonymous" to the script tag and make sure the host sends an Access-Control-Allow-Origin header. If the host does not send it, you cannot get details in your logger, so read the real error in the browser Console instead.
Does the crossorigin attribute break scripts?
It can. With crossorigin="anonymous", the browser requires a valid CORS header from the host. If the header is missing, the script is blocked and will not run, so check the header before adding the attribute.
Is 'Script error.' serious?
Not by itself, which is why the impact is low. It is serious if the hidden script powers a form, checkout, chat button or tracking tag, because those failures cost leads or conversions.
How can I see the real error behind 'Script error.'?
Open DevTools and check the Console while you use the page. Browsers show the full error there, even when your logger only receives 'Script error.' You can also test the script in a duplicate environment with other tags turned off.
Can FunnelGuard tell me what caused a Script error?
Only partly. It captures the 'Script error.' message when it appears, but the browser hides the detail from it too. Its journey, tracking and lead checks still show whether the error broke something that matters.
Related issues
- PRF-116Uncaught JavaScript exception on page loadFix guide
- PRF-117Console error on a funnel stepFix guide
- PRF-124CORS error blocking API call from the pageFix guide
- PRF-125Content Security Policy blocks a needed script or tagFix guide
- PRF-134Button does nothing on click (dead click)Fix guide
- PRF-135Form submits but shows no feedback (silent failure)Fix guide