Debugging Intermediate
Use Claude Code with Chrome DevTools MCP to debug web applications interactively. Inspect the DOM, execute JavaScript in the page context, read console messages, interact with elements, take diagnostic screenshots, and build live debugging workflows.
1. DOM Inspection and Manipulation
Claude Code can inspect the page structure using DOM snapshots and accessibility trees:
# Get a snapshot of the page DOM Claude > Take a DOM snapshot of the current page and tell me what form elements are on the page # Find specific elements Claude > Run JavaScript to find all buttons on the page and list their text content # Modify the DOM for debugging Claude > Run JavaScript to add a red border to all elements with the class "error" so I can see them
// Claude runs this in the browser via evaluate_script: document.querySelectorAll('.error').forEach(el => { el.style.border = '3px solid red'; el.style.backgroundColor = 'rgba(255, 0, 0, 0.1)'; }); // Get computed styles of an element const el = document.querySelector('#main-header'); const styles = window.getComputedStyle(el); JSON.stringify({ display: styles.display, position: styles.position, zIndex: styles.zIndex, });
2. JavaScript Execution in Page Context
One of the most powerful capabilities is running JavaScript directly in the browser page. Claude Code uses the evaluate_script tool for this:
# Check application state Claude > Run JavaScript to check what's in localStorage for this application # Inspect React/Vue/Angular state Claude > Run JavaScript to get the React component state of the element with id "user-profile" # Test a function Claude > Call the formatPrice function with the value 1999 and show me the output # Check for errors Claude > Run window.onerror to see if there are any unhandled errors, and also check if any promises are rejected
3. Console Message Reading
Read console output without opening DevTools manually:
# List all console messages Claude > Show me all console messages from this page # Filter for errors Claude > Show me only console errors and warnings. Are there any JavaScript errors on this page? # Watch for new messages Claude > Click the "Submit" button and then show me any new console messages that appeared
4. Element Clicking and Form Filling
Interact with page elements to reproduce bugs or test functionality:
# Fill a form to reproduce a bug Claude > Fill the login form with email "test+special@example.com" and password "test123" and click Submit. Then take a screenshot and show me any console errors. # Fill multiple form fields at once Claude > Fill the registration form with these values: - First Name: John - Last Name: Doe - Email: john@example.com - Phone: 555-0123 # Interact with dropdowns and checkboxes Claude > Select "Express Shipping" from the shipping method dropdown and check the "Gift wrap" checkbox
5. Screenshot-Based Debugging
Use screenshots to visually inspect the page state at different points:
# Debug a layout issue Claude > Take a screenshot of the page. Is the footer overlapping the main content? What CSS issues do you see? # Check responsive layout Claude > Resize the page to 375x812 (iPhone size) and take a screenshot. Is the navigation menu properly collapsed? # Before/after comparison Claude > Take a screenshot, then click the "Toggle Dark Mode" button, and take another screenshot. Compare the two.
6. Live Debugging Workflow
Here is a complete debugging workflow using Claude Code with DevTools:
-
Identify the issue
"Users report that the checkout button doesn't work on mobile."
-
Reproduce the environment
Claude Code Session
Claude > Emulate an iPhone 14 and navigate to /checkout -
Take a screenshot and inspect
Claude Code Session
Claude > Take a screenshot. Is the checkout button visible? Also check for console errors. -
Investigate the root cause
Claude Code Session
Claude > Run JavaScript to check the computed styles of the checkout button. Is it hidden or covered by another element? -
Test the fix
Claude Code Session
Claude > Run JavaScript to set the checkout button's z-index to 1000 and position to relative. Take a screenshot to verify the fix works.
Practice Debugging
Navigate Claude Code to a web page, take a screenshot, inspect the DOM, run JavaScript to check the page state, and read console messages. Build familiarity with the debugging tools before moving to performance analysis.
Next: Performance →
Lilly Tech Systems