Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Uncaught JavaScript exception on page load: how to find and fix it

PRF-116High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

JavaScript is the code that makes a page interactive. When a script hits something it cannot do, such as reading a property of undefined or calling a function that does not exist, it throws an error. If nothing catches that error, it is called an uncaught exception. The browser prints it in the console and stops running that script from that line onward.

The damage depends on what the failed script was responsible for. A visitor sees a normal-looking page, but something behind it is dead. You may not notice because the page still loads.

What an early error can break
  • Form validation or submit handlers that never attach, so the button does nothing or the form posts incorrectly
  • Buttons for chat, booking, menus or add to cart that never respond
  • Tracking tags and pixels that were set to start after the failing code, so conversions are not reported to ad platforms
  • Consent banners that fail to show, which can leave tags blocked or running without the right consent state
  • Page content that is meant to be rendered by script, such as pricing, product options or a checkout step
How one error can stop a funnel
  1. Page loadsHTML and CSS display normally
  2. Script throwsUncaught TypeError stops the script
  3. Form handlerNever attached
  4. Tracking tagNever fires
  5. Lead or saleNot completed or not reported

The script fails at one line, so everything it should have done afterwards is lost.

A page that looks fine but errors underneath

The visitor sees the page, while the console shows an uncaught error.

Find the error in your browser
  1. Open DevTools

    Press F12, or Ctrl+Shift+J (Windows) or Cmd+Option+J (Mac) in Chrome, to open the Console.

  2. Reload the page

    Errors that happen on load only appear if the console is open before the page loads. Tick Preserve log if the page redirects.

  3. Read the red entries

    Note the message and the file and line on the right, for example app.js:42. Click it to open the code in the Sources panel.

  4. Identify who owns the script

    Check the URL. Your theme or bundle, a plugin, a tag manager container or a third-party domain each have a different owner and fix.

  5. Repeat on key pages and devices

    Test the landing page, form page and checkout, in a private window with extensions off, and on mobile. Browser extensions can cause errors that visitors never see.

The fix depends on the message and who owns the script. Start with the most common causes in the table, then use the platform steps.

Common messages and likely causes
MessageLikely causeTypical fix
Cannot read properties of nullCode looks for an element that is not on the page yet or was renamedRun the code after the page is ready, or check the element exists first
x is not definedA library did not load, loaded later, or was blockedLoad the library first, fix its URL, or remove code that needs it
Unexpected token '<'A script URL returned an HTML page, often a 404Fix the file path or redeploy the missing file
Unexpected tokenSyntax error, or a script was changed or minified badlyRestore the last working version of the file or snippet
$ is not a function / jQuery is not definedA script using jQuery runs before jQuery loadsLoad jQuery first or remove the dependent script
Fix by platform
  1. Find the source file

    In the console error, check the path. /wp-content/plugins/name/ points to a plugin, /wp-content/themes/name/ to your theme.

  2. Isolate the cause

    On a staging copy, deactivate plugins one by one, or switch to a default theme, and reload until the error disappears.

  3. Check optimisation settings

    If the error began after turning on minify, combine or delay JavaScript in a caching or speed plugin, switch that option off, clear the cache and retest.

  4. Update or replace

    Update the plugin or theme, or contact its developer with the exact error text, or replace it.

Run DOM code safely after loadjavascript
document.addEventListener('DOMContentLoaded', function () {
  var form = document.querySelector('#lead-form');
  if (!form) return; // element missing on this page, do nothing
  form.addEventListener('submit', function (e) {
    // your handler
  });
});
Log uncaught errors to your own endpointjavascript
window.addEventListener('error', function (event) {
  navigator.sendBeacon('/log-js-error', JSON.stringify({
    message: event.message,
    source: event.filename,
    line: event.lineno,
    page: location.href
  }));
});
Console before and after the fix

Before

  • Red Uncaught TypeError on every load
  • Form button sometimes does nothing
  • Conversion tag missing from the network tab

After

  • Console has no uncaught errors from your own code
  • Form submits and shows a confirmation
  • Conversion tag request appears after submit
Confirmation checks
  • Reload the page with the console open and no red uncaught errors from your own scripts
  • Test in a private window with extensions off, on desktop and mobile
  • Submit a test lead and confirm the thank-you step and the email or CRM entry
  • Check the Network tab or your tag tool to confirm the tracking requests fire
  • Clear your site and CDN cache first, so you are not testing an old file

Most load errors appear after a change: a theme or plugin update, a new tag, a speed setting or a deploy. Make the console check part of every change.

Habits that help
  • Test on a staging copy and check the console before publishing
  • Change one thing at a time so the cause is obvious
  • Keep a record of which scripts and tags are on each funnel page
  • Use GTM versions so you can roll back a bad tag quickly
  • Re-test key pages after every update, deploy or tag change
  • Monitor your funnel pages on a schedule instead of waiting for a customer to complain
How an unnoticed load error unfolds (example)
  1. Day 0

    A plugin update changes a script and it starts throwing on load

  2. Day 1

    The page looks normal, so nobody notices

  3. Day 4

    Reported conversions drop, but the cause is unclear

  4. Day 5

    Someone opens the console, finds the error and rolls back

FunnelGuard detects this today. When its robot visitor loads your pages and runs your journeys on a schedule, it captures page errors, meaning uncaught JavaScript exceptions raised by the page. A failure is re-checked from a second region before one alert goes out, with a screenshot and a likely cause.

If the error only happens after clicking submit, a dead button, or a script blocked by security rules, see the related guides below.

Questions people ask

Why is my website showing an uncaught JavaScript error?

A script on the page hit a problem, such as reading a missing element or calling a function that is not defined, and nothing handled it. Open the Console in DevTools and reload to see the message, file and line. Those tell you whether your theme, a plugin, a tag or a third-party script is the cause.

How do I find which script is causing the error?

Open DevTools, reload with the Console open and click the file and line link beside the red error. The URL shows who owns the script. If it is minified, use source maps or disable plugins, apps or tags one at a time until the error disappears.

Does a JavaScript error stop my form from working?

It can. If the error happens before the form's script attaches its handlers, validation or submit code may never run. Some forms still post normally without JavaScript, so test with a real test submission rather than guessing.

Can a JavaScript error stop my tracking pixels?

Yes. If a tag is set to start from code that runs after the failing line, it never fires, so conversions are not reported to GA4 or ad platforms. Tags loaded separately may still work, so check the Network tab for the tracking requests.

Why do I see errors in my console that visitors do not?

Browser extensions inject their own scripts and can cause errors, often shown as chrome-extension:// files. Test in a private window with extensions disabled to see what visitors see.

Do all console errors hurt conversions?

No. Some are harmless, like a missing icon or a blocked ad script. Focus on uncaught errors from your own scripts on funnel pages, and then check whether forms, buttons and tags still work.

How can I be alerted when a JavaScript error appears on my site?

You can add your own error logging, or use monitoring that loads your pages on a schedule. FunnelGuard captures uncaught page errors during its scheduled journey runs and sends one alert, after re-checking from a second region, with a screenshot and a likely cause.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: pageerror captured.

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.