How to Fix JavaScript Console Errors on Your Website
JavaScript console errors are uncaught exceptions, failed script loads and logged errors that appear when a browser renders your pages. This audit renders your pages in a headless browser and flags the site when half or more of them log errors. By the end of this guide you will have found the errors, traced each to its source (your code, a plugin, or a third-party tag), fixed or removed them, and confirmed the pages render cleanly.

Why it matters
An uncaught error stops the script that threw it. Anything after that point may never run, including menus, product grids, reviews, lazy-loaded images, consent banners or the JSON-LD that a script injects. Googlebot and other crawlers that render JavaScript see the same broken page, so content and links that depend on that script can drop out of the index and out of AI-generated answers.
Users get dead buttons and failed checkouts. Recurring errors also hide new ones, so real regressions go unnoticed.
What you need
Step-by-step fix
Reproduce the errors in DevTools
Open a flagged URL in a private/incognito window so extensions don't add noise. Press F12, open the Console tab, set the level filter to show Errors, tick Preserve log, then hard-reload with Ctrl+Shift+R (Cmd+Shift+R on Mac). Write down each red message, its file and line number, and whether it appears on every page or only some templates (home, product, blog post).
Sort each error by its source
Click the file link on the right of each error to see where it comes from. Most errors fall into one of these groups:
- Your code: theme or app bundle, e.g.
TypeError: Cannot read properties of null - Failed resource:
Failed to load resource: 404ornet::ERR_BLOCKED_BY_CLIENT - Security policy:
Refused to load the script ... Content Security Policyor mixed content (http on an https page) - Third-party tags: chat widgets, ad, analytics or A/B testing scripts on other domains
- Framework: hydration mismatches, minified React errors such as #418 or #423
Fix null and load-order errors in your own scripts
The most common error comes from a script that looks for an element that doesn't exist on that template, or runs before the DOM is ready. Load scripts with defer, and check that the element exists before you use it. Wrap optional features so one failure can't stop the rest of the file.
<script src="/assets/main.js" defer></script>
// main.js
const btn = document.querySelector('#newsletter-btn');
if (btn) {
btn.addEventListener('click', openNewsletter);
}
try {
initCarousel();
} catch (e) {
// report to your monitoring tool instead of breaking the page
}Repair missing files and blocked resources
For 404 script errors, either restore the file or delete the <script> tag that references it. Leftover tags from uninstalled apps and plugins are the usual cause. Change any http:// script URLs to https://.
If your Content-Security-Policy blocks a script you need, add its origin to script-src. If you don't need the script, remove it rather than allowing it.
Content-Security-Policy: script-src 'self' https://www.googletagmanager.com https://cdn.example.com;
Fix or remove failing third-party tags
In Google Tag Manager, open Preview mode on the flagged URL, find the tag that fires just before the error, then pause it or fix its trigger so it only fires on pages where its target element exists. For vendor widgets, update to the vendor's current embed snippet. If nobody uses the tool any more, delete it.
Errors thrown inside third-party scripts still count, so you can't ignore them.
Check the pages in a headless browser
The audit renders pages without a user, cookies or consent, so test the same way. This Playwright script prints uncaught exceptions, console.error messages and failed requests for each URL. Run npm i -D playwright && npx playwright install chromium, then node check-errors.mjs.
import { chromium } from 'playwright';
const urls = ['https://example.com/', 'https://example.com/products/widget', 'https://example.com/blog/post'];
const browser = await chromium.launch();
for (const url of urls) {
const page = await browser.newPage();
const errors = [];
page.on('pageerror', e => errors.push('Uncaught: ' + e.message));
page.on('console', m => m.type() === 'error' && errors.push('Console: ' + m.text()));
page.on('requestfailed', r => errors.push('Failed: ' + r.url()));
await page.goto(url, { waitUntil: 'networkidle' });
console.log(url, errors.length ? errors : 'OK');
await page.close();
}
await browser.close();Deploy, clear caches and re-run the audit
Publish the fixes, then purge your CDN and any page-cache or minification plugin so the old bundles stop being served. Re-run the headless script against a sample from each template. Then re-run this audit and confirm fewer than half of the rendered pages report errors.
The goal is zero.
Platform-specific notes
WordPress
Most errors come from plugin or theme conflicts. Install the Health Check & Troubleshooting plugin and use Troubleshooting Mode to turn plugins off for your session only. Re-enable them one at a time to find the culprit. Add define('SCRIPT_DEBUG', true); to wp-config.php to load unminified core scripts with readable line numbers. Clear caches in WP Rocket, LiteSpeed or Autoptimize, because 'delay/combine JS' settings often cause errors.
Shopify
Look in Online Store > Themes > ... > Edit code > layout/theme.liquid and snippets/ for script tags left behind by uninstalled apps, and remove them. Check app embeds under Customize > App embeds and turn off the ones you no longer use. Third-party pixels added under Settings > Customer events run in a sandbox, so check their errors there separately.
Wix / Webflow
You can't edit platform scripts, so focus on what you added. In Wix, check Settings > Custom Code. In Webflow, check Site settings > Custom code and each page's Before </body> tag field. Errors in the platform's own files usually clear after you republish or remove a broken custom embed.
Next.js / React
Hydration errors (minified React #418, #423, #425) mean the server HTML differs from the client render. Common causes are dates, Math.random, window checks during render, or invalid nesting such as a <div> inside a <p>. Run next dev to see the full error message, and move browser-only code into useEffect or load it with dynamic(..., { ssr: false }).
Cloudflare
Rocket Loader, Email Address Obfuscation and Auto Minify (deprecated) can reorder or rewrite scripts and introduce errors. To test, turn Rocket Loader off under Speed > Optimization > Content Optimization, purge the cache, and re-check the page before you change any code.
Check that it worked
✅ How to verify
- Hard-reload each template in an incognito window with the DevTools Console set to Errors, and confirm the console is empty.
- Run the Playwright script from step 6 and confirm every URL prints OK.
- In Google Search Console, use URL Inspection > Test live URL > View tested page > More info > JavaScript console messages, and confirm no errors are listed.
- Re-run this audit and confirm the JavaScript console errors check passes.
⚠️ Common mistakes
- Testing only in your own logged-in browser, where cached files, cookies and accepted consent hide errors that bots and new visitors see.
- Wrapping everything in an empty try/catch or overriding console.error to hide messages. The feature is still broken, only now it fails silently.
- Fixing the source file but not purging the CDN, page cache or minified bundle, so the old broken file keeps being served.
- Ignoring third-party script errors because they're 'not our code', even though they still stop scripts on your page and count against it.
Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.
Check my site freeFAQ
Do JavaScript console errors hurt SEO?
Not directly, because Google doesn't penalise a console message. They hurt indirectly when an error stops content, links or structured data from rendering. Googlebot then indexes the incomplete page.
Should I fix warnings as well as errors?
This check counts errors. Warnings such as deprecation notices don't fail it, but they often turn into errors when a browser or library updates, so fix them when you can.
Why do I see errors that my visitors don't?
Browser extensions inject scripts that throw their own errors. Test in an incognito window with extensions off, or with the headless script, to see only your site's errors.
How do I find which plugin or app causes a JS error?
Click the file link next to the error in DevTools. The path usually names the plugin folder, for example /wp-content/plugins/name/, or the app's domain. If it's a bundled file, turn plugins or app embeds off one at a time until the error stops.
How to Serve Your Website Through a CDN Near Your Audience
How to Fix Excessive DOM Size: Trim Pages Under 1,500 Nodes
How to Enable IndexNow So New Pages Are Submitted on Publish
How to Fix Low Text Contrast and Unlabeled Form Fields (WCAG)
How to Fix an Indexed Staging Site in Google and Bing
How to Check Googlebot Activity in Your Server Logs