How to Debug JavaScript Console Errors on Mobile: Tools, Common Errors and Fixes

Your site works perfectly on your laptop, and then a customer messages you a screenshot of a blank section on their phone. The code is the same, so what happened? Very often, a JavaScript error on the phone stopped the script, and you cannot see it because phones do not show a developer console by default. This guide explains how to see those errors, how to read them, and how to fix the most common ones.

The methods below work for plain JavaScript sites, WordPress themes and plugins, and single-page apps. They assume basic familiarity with browser developer tools.

Why errors differ on mobile

  • Different browsers and versions. An older Android WebView or an iOS Safari version may not support syntax or APIs you used, such as optional chaining or a newer array method.
  • Touch, not mouse. Events such as hover, mouseenter and right-click behave differently or do not fire.
  • Slow networks and limited memory. Scripts load late, time out or are killed, which exposes race conditions you never see on fast broadband.
  • Stricter security. Mixed content, third-party cookie rules and content security policies can block requests that work elsewhere.
  • In-app browsers. Links opened inside social apps or WhatsApp use their own web views, with quirks of their own.

Method 1: emulate a phone in desktop DevTools

Start here because it costs nothing. In Chrome or Edge, open DevTools and use the device toolbar to choose a phone size, set network throttling to “Fast 4G” or “Slow 4G” and CPU throttling to 4x slowdown. Reload and watch the Console tab. This catches layout and timing issues, but it still runs the desktop engine, so it cannot reproduce engine-specific bugs.

Method 2: remote debugging a real Android phone

  1. On the phone, enable Developer options and turn on USB debugging.
  2. Connect the phone to your computer with a USB cable and accept the debugging prompt.
  3. Open Chrome on the computer and visit chrome://inspect under the Devices tab.
  4. Open your page in Chrome on the phone. It appears in the list; click “inspect”.
  5. You now have the full console, network panel, elements panel and debugger, working on the real device.

This is the most reliable way to debug Android Chrome and Android WebView content. It also lets you take screenshots, view network timing and set breakpoints on the phone’s own engine.

Method 3: remote debugging iPhone Safari

On an iPhone, go to Settings, then Safari, then Advanced, and turn on Web Inspector. Connect the iPhone to a Mac with a cable, open Safari on the Mac, enable the Develop menu in its settings, and choose your device and page from the Develop menu. Safari’s Web Inspector then shows the console and network for the phone. If you do not have a Mac, use an on-device console (below) or a cloud testing service.

Method 4: an on-device console

When you cannot attach a cable, a small library shows a console right inside the page. Eruda and vConsole are popular choices. Add one only on a test or staging page, never leave it in production.

<script src="https://cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>

A small gear icon appears; tap it to see logs, network requests, elements and storage. A safer pattern is to load it only when the URL contains a debug flag you control.

Method 5: capture errors from real users

You cannot plug a cable into a customer’s phone. Instead, catch errors in code and send them somewhere you can read them.

function report(payload) {
  // send to your own endpoint; keep it small and privacy-safe
  navigator.sendBeacon('/log-error', JSON.stringify(payload));
}

window.addEventListener('error', function (e) {
  report({
    type: 'error',
    message: e.message,
    source: e.filename,
    line: e.lineno,
    col: e.colno,
    ua: navigator.userAgent,
    url: location.href
  });
});

window.addEventListener('unhandledrejection', function (e) {
  report({
    type: 'promise',
    message: String(e.reason),
    ua: navigator.userAgent,
    url: location.href
  });
});

Hosted tools such as Sentry do this for you with source-map support and grouping. Whichever you choose, avoid logging personal data, and tell users what you collect if your privacy policy requires it. Note that errors from scripts on other domains often show only “Script error.” unless the script is served with CORS headers and the crossorigin attribute.

How to read an error message

A console error usually has three useful parts: the error type, the message and the file and line number (with a stack trace). Start at the top of the stack trace, which is where the error occurred, and work down to the code that called it. If the file is minified, use source maps so the browser shows your original code.

Common errors and what to do about them

Error messageUsual causeFix
TypeError: Cannot read properties of undefined (reading ‘x’)Using a value before it exists, such as an element not yet in the DOM or API data not yet loadedCheck the value exists, wait for DOMContentLoaded or the data, use optional chaining where supported
ReferenceError: x is not definedMisspelled variable, script load order wrong, or a library failed to loadCheck spelling, script order and the network tab for failed script requests
SyntaxError: Unexpected tokenNewer syntax in an older browser, a stray character, or an HTML page returned instead of JSON or JSTranspile for target browsers, check the response in the network tab
Failed to load resource: 404Wrong path, case-sensitive file name, removed fileCorrect the URL, check build output and caching
Blocked by CORS policyThe API server does not allow your originConfigure CORS headers on the server; do not disable security in production
Mixed Content: blockedAn HTTPS page loading an HTTP script, image or APIUse HTTPS URLs for every resource
Uncaught (in promise)A rejected promise with no catch handlerAdd try/catch around await or a .catch() handler
Refused to execute inline script (CSP)A Content Security Policy blocks inline codeMove scripts to files or add nonces, and review the policy

Mobile-specific traps

  • Hover-only interactions. Menus and tooltips that open on hover never open on touch. Use click or tap, and test with the touch emulation on.
  • Scroll and resize handlers. Frequent events can slow phones and cause jank. Throttle or debounce them, and prefer passive listeners.
  • The 100vh problem. On mobile browsers, the viewport height changes as the address bar shows and hides. Use dvh units or measure with JavaScript.
  • Storage limits and private mode. localStorage can throw in private browsing or when blocked. Wrap access in try/catch.
  • Memory pressure. Large images, many listeners and heavy libraries can make a low-end phone kill the tab. Test on a budget device.
  • Autoplay and permissions. Audio, video, camera and clipboard APIs need a user gesture or permission on mobile.

A step-by-step debugging routine

  1. Reproduce. Get the exact phone model, OS version, browser and URL from the user if you can.
  2. Check the layout first. View the page at the phone’s width; many “JavaScript bugs” are really a hidden or overflowing element. A phone-based tester such as the free Dev Browser app (see the Dev Browser guide) makes it quick to view a page at mobile, tablet and desktop widths.
  3. Open the console through remote debugging or an on-device console, and reload with the cache cleared.
  4. Fix the first error. Later errors are often side effects of the first.
  5. Check the network tab for failed, blocked or slow requests.
  6. Test the fix on a real device, on a slow network, and in a second browser.
  7. Add monitoring so the next error reaches you before a customer complains.

How errors affect performance and SEO

Script errors can break interactivity, delay rendering and stop content from loading, which hurts users and can hurt the page Google sees. Slow input response also shows up in Core Web Vitals; our article on fixing LCP, INP and CLS on mobile covers that. If content depends on a script that fails for crawlers, read mobile-first indexing: what developers must check. For layout problems rather than script errors, see CSS breakpoints, media queries and container queries and the responsive web design testing checklist. More tools are listed on the products page.

Quick checklist

  • Emulate the phone and throttle network and CPU in DevTools.
  • Remote-debug a real Android phone with chrome://inspect, or iPhone Safari with a Mac.
  • Use an on-device console only on test pages.
  • Log real-user errors with window error and unhandledrejection handlers.
  • Fix the first error, then recheck the rest.
  • Serve every resource over HTTPS and configure CORS correctly.
  • Test on at least one low-end Android device.

Frequently asked questions

Can I see the console on a phone without a computer?

Yes, with an on-device console library such as Eruda added to your test page, or a cloud testing service. Standard mobile browsers do not expose the console on their own.

Why do I only see “Script error.”?

The browser hides details of errors from scripts served from another origin. Serve them with CORS headers and add the crossorigin attribute to the script tag.

Is it safe to leave console logging in production?

Keep it minimal. Do not log tokens, personal data or internal details, and remove debug tools like on-device consoles.

How do I debug WebView inside an Android app?

The app must enable WebView debugging in a debug build. Then the WebView appears in chrome://inspect like a normal tab.

Disclaimer: Browser tools and menus change between versions. The steps here are general guidance; consult the current Chrome, Safari and Android documentation, and avoid collecting user data without a lawful basis and clear disclosure.

Leave a Reply

Share Your Love