Skip to content
FunnelGuard

Fix guide by FunnelsGuard

'Script error.' with no detail: how to find and fix it

PRF-121Low impactPartlyBy FunnelGuardPublished Updated
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.

What your error handler typically receivesjavascript
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

How a hidden error can cost a lead
  1. Page loadsThird-party script requested from another domain
  2. Script throwsBrowser reports only 'Script error.'
  3. Widget or tag failsForm, chat or tracking does not run
  4. 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

Find out whether you have cross-origin script errors
  1. 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.

  2. List your third-party scripts

    Open the page, then DevTools > Network > filter JS. Note every script whose domain differs from your own.

  3. 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.'

  4. 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 tag with crossoriginhtml
<script src="https://cdn.example.com/widget.js" crossorigin="anonymous"></script>
Fix by platform
  1. Add crossorigin to external scripts

    Add crossorigin="anonymous" to each script tag loaded from another domain that sends CORS headers.

  2. 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.

  3. 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.

WordPress: add crossorigin to one script handlephp
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);
Nginx: allow CORS for scripts on your own CDN hostnginx
location ~* \.js$ {
  add_header Access-Control-Allow-Origin "https://www.example.com";
}

How to confirm it's fixed

Confirmation checks
  • 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
What your logger sees

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

Prevention habits
  • 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.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: captured, no detail.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.