User Agents

Web browsers and everyday web tech, explained

Troubleshoot JavaScript Errors in Edge DevTools

· 6 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to use Microsoft Edge DevTools to find and fix JavaScript errors in your web pages. You'll learn to read the Console, use breakpoints, and inspect network requests—all without leaving the browser. Before starting, make sure you have a page that reproduces the error and that you can access Edge's developer tools (press F12 or right-click and select 'Inspect').

What You'll Need

  • Microsoft Edge (any recent version) installed on your computer.
  • A web page or web app that exhibits the JavaScript error you want to fix.
  • Basic familiarity with HTML, CSS, and JavaScript syntax.

Step-by-Step

  1. Open DevTools. Navigate to the page with the error. Press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac). Alternatively, right-click anywhere on the page and choose 'Inspect'.
  2. Go to the Console tab. Click the 'Console' tab in the top toolbar. If you don't see it, click the '>>' (more tabs) icon to reveal it. The Console shows all JavaScript errors, warnings, and log messages.
  3. Identify the error message. Look for red text—these are errors. Each error typically includes a message (e.g., 'Uncaught TypeError: Cannot read property 'x' of undefined') and a link to the source file and line number (e.g., 'script.js:12').
  4. Click the error link. Clicking the file:line link opens the 'Sources' panel and jumps to that exact line. The line will be highlighted, and you can see the surrounding code.
  5. Read the stack trace. In the Console, errors often have a stack trace (a list of function calls that led to the error). Expand the error to see the full trace. This tells you which function called which, helping you trace the origin.
  6. Set breakpoints. In the Sources panel, click the line number where you suspect the bug. A blue arrow appears, indicating a breakpoint. Reload the page (F5). Execution will pause at that line, and you can inspect variables in the 'Scope' pane on the right.
  7. Step through code. While paused, use the 'Step over' (F10), 'Step into' (F11), and 'Step out' (Shift+F11) buttons in the toolbar to execute code line by line. Watch how variable values change in the 'Scope' or 'Watch' panes.
  8. Use the Watch panel. In the Sources panel, click the 'Watch' tab (or the plus icon) to add expressions. Type a variable name (e.g., myObject) and press Enter. Its current value is displayed, updating as you step through.
  9. Check network requests. If the error is related to missing data or failed API calls, open the 'Network' tab. Reload the page. Look for requests highlighted in red (failed). Click one to see the response status, headers, and preview. A 404 or 500 error often explains why a variable is undefined.
  10. Use the 'Sources' file tree. In the Sources panel, expand the file tree on the left to see all loaded scripts. Click a file to view its content. You can search within a file using Ctrl+F (Cmd+F on Mac) to find specific functions or variables.
  11. Edit code live. In the Sources panel, you can edit a JavaScript file directly by clicking on it and making changes. Press Ctrl+S (Cmd+S) to save. The change is applied immediately without reloading—this is great for quick tests.
  12. Use the 'Console' to test expressions. Type any JavaScript expression in the Console and press Enter to evaluate it. For example, type typeof myVariable to see if it's undefined, or call a function to see its output.
  13. Check for syntax errors. If the Console shows 'Uncaught SyntaxError', there is a typo or missing bracket. The error message will point to the exact location. Fix it in your code editor, save, and reload.
  14. Use 'Pause on exceptions'. In the Sources panel, click the 'Deactivate breakpoints' icon (a pause symbol with a circle) to toggle 'Pause on exceptions'. When enabled, execution stops automatically whenever an exception is thrown, even if you haven't set a breakpoint.
  15. Inspect the call stack. When paused, the 'Call Stack' pane on the right shows the chain of function calls. Click any frame to see the code at that point and the local variables at that moment.

Common Mistakes

  • Ignoring warnings. Yellow warnings are not errors but can indicate potential issues (e.g., deprecated APIs). Address them to prevent future errors.
  • Forgetting to reload after edits. If you change code in an external editor, you must reload the page to see the effect. DevTools' live edit applies only to changes made in the Sources panel.
  • Confusing 'undefined' with 'null'. An error like 'Cannot read property of undefined' means the variable exists but has no value. Check if you assigned it correctly.
  • Setting breakpoints on the wrong line. Make sure the breakpoint is on a line that actually executes (not a blank line or a comment).
  • Not checking the Network tab. Many JS errors are caused by failed AJAX requests. Always check the Network tab for failed requests before debugging logic.

Tips

  • Use the 'Preserve log' checkbox in the Console to keep messages from previous page loads—useful when the error happens during initial load.
  • In the Console, use console.log() strategically to output variable values at key points. Remove these logs later.
  • Use the 'Group by message' option in Console settings to collapse similar errors.
  • If you're debugging a minified file, click the '{}' (Pretty-print) button in the Sources panel to format the code for readability.
  • Use the 'Coverage' tool (in the 'More tools' menu) to see which lines of JavaScript are actually executed—helps identify dead code.

Troubleshooting

If the error is not appearing in the Console, try the following:

  • Clear the console. Click the 'Clear console' icon (a circle with a slash) or press Ctrl+L. Then reload the page to see fresh errors.
  • Check if the error is from an extension. Disable browser extensions (type edge://extensions in the address bar) and reload. Some extensions inject scripts that cause errors.
  • Use a clean profile. Open Edge in InPrivate mode (Ctrl+Shift+N) to rule out cached data or extensions.
  • Verify the file is loaded. In the Network tab, check that your JavaScript file is loaded successfully (status 200). If it's 404, the file path is wrong.
  • If breakpoints don't trigger, ensure the script is not cached. Open DevTools, go to Network tab, and check 'Disable cache' while DevTools is open.
  • If the error only happens in production, it may be due to minification. Use the source map (if available) by clicking the 'Sources' tab and looking for a .map file.

Frequently Asked Questions

Why does the Console show 'Uncaught ReferenceError: x is not defined'?

This means you tried to use a variable or function named 'x' that hasn't been declared in the current scope. Check for typos in the variable name, or ensure the variable is declared with let, const, or var before use.

How do I see the value of a variable when paused at a breakpoint?

In the Sources panel, while paused, hover over the variable name in the code to see a tooltip. Alternatively, add it to the 'Watch' panel or type it in the Console (the Console evaluates in the current context).

Why does my breakpoint not hit?

Possible reasons: the line is not executed (e.g., inside an if block that is false), the script is cached (disable cache in Network tab), or the breakpoint is set on a line that is not a valid statement. Also ensure the script is not minified without a source map.

How can I debug an error that happens during page load?

Set a breakpoint on the first line of your script, or use 'Pause on exceptions'. Also, enable 'Preserve log' in the Console to keep errors from the initial load after you reload.

What does 'Failed to load resource: the server responded with a status of 404' mean?

This is not a JavaScript error but a network error. A requested resource (like a script or API endpoint) was not found. Check the URL in the Network tab and verify the file exists on the server.

Can I edit JavaScript directly in DevTools and save the changes?

Yes, you can edit in the Sources panel, but changes are only applied to the current session. To persist changes, copy the modified code back to your source files. DevTools does not modify files on disk.