Console Monitoring: Catch JavaScript Errors Before Users Do
A practical Fusebox guide to console monitoring.
Console Monitoring: Catch JavaScript Errors Before Users Do
Published: January 2024
Reading time: 6 minutes
The browser console is where JavaScript speaks. Errors, warnings, logs - they all tell you what's really happening on any website. Here's how to listen.
What the Console Reveals
Every website logs to console:
- Errors: Broken code
- Warnings: Potential issues
- Info: Developer messages
- Network: Failed requests
- Security: Mixed content, CORS
Most users never see this. Developers who monitor it catch bugs early.
Types of Console Messages
1. Errors (Red)
Uncaught TypeError: Cannot read property 'map' of undefined
at renderList (app.js:45)
What it means: Code tried to use .map() on something that doesn't exist Impact: Feature broken
2. Warnings (Yellow)
DevTools failed to load source map: 404 main.js.map
What it means: Debug files missing Impact: Harder to debug
3. Info Logs (Black)
[Analytics] Page view tracked: /products
User authenticated successfully
Cache hit for API request
What it means: Developer left helpful logs Impact: Insight into app behavior
4. Network Errors
GET https://api.example.com/users 404 (Not Found)
Access to fetch blocked by CORS policy
Mixed Content: HTTPS page loaded HTTP resource
What it means: Resource loading failed Impact: Missing data/functionality
Real Developer Scenarios
Scenario 1: E-commerce Checkout Broken
Console shows:
Uncaught ReferenceError: Stripe is not defined
at checkout.js:23
Failed to load resource: stripe.com/v3/ net::ERR_BLOCKED_BY_CLIENT
Problem: Ad blocker blocking Stripe Solution: Detect and warn users
Scenario 2: Slow React App
Console shows:
Warning: Each child should have a unique "key" prop
Warning: Can't perform state update on unmounted component
[Violation] 'click' handler took 1523ms
Problems:
- Missing keys = unnecessary re-renders
- Memory leaks from unmounted updates
- Slow event handlers
Scenario 3: API Integration Issues
Console pattern:
POST /api/login 200 OK
GET /api/user 401 Unauthorized
Error: Request failed with status 401
Uncaught (in promise) TypeError: Cannot read property 'name' of null
Flow: Login worked, but token not sent with next request
Common JavaScript Errors
1. Cannot Read Property of Undefined
// Code tries:
user.profile.name
// But user.profile is undefined
Uncaught TypeError: Cannot read property 'name' of undefined
Fix: Check if properties exist
user?.profile?.name // Optional chaining
2. X is not a Function
// Code tries:
data.forEach(item => ...)
// But data is not an array
Uncaught TypeError: data.forEach is not a function
Common cause: API returned object instead of array
3. CORS Errors
Access to fetch at 'https://api.example.com' from origin
'https://mysite.com' has been blocked by CORS policy
Issue: Server doesn't allow your domain Fix: Server needs proper CORS headers
4. Mixed Content
Mixed Content: The page was loaded over HTTPS, but requested
an insecure resource 'http://...'
Issue: HTTPS page loading HTTP resources Impact: Browsers block insecure requests
Advanced Console Patterns
1. Performance Warnings
[Violation] 'setTimeout' handler took 850ms
[Violation] Forced reflow while executing JavaScript
[Violation] Avoid using document.write()
What these reveal:
- Slow code blocking UI
- Layout thrashing
- Bad practices
2. Framework-Specific
React:
Warning: Can't call setState on unmounted component
Warning: useEffect missing dependency: 'userId'
Vue:
[Vue warn]: Property "user" is not defined
[Vue warn]: Avoid mutating prop directly
Angular:
ERROR Error: ExpressionChangedAfterItHasBeenChecked
ERROR TypeError: Cannot read property 'nativeElement' of undefined
3. Security Warnings
Warning: A cookie was set with SameSite=None but without Secure
Blocked autoplaying video with sound
Feature Policy: Camera access denied
Debugging Techniques
1. Trace Error Origins
// Error shows:
Uncaught TypeError at processData (bundle.js:1:2847)
// Steps:
1. Click the file link
2. Pretty-print minified code
3. Set breakpoint
4. Reproduce error
5. Inspect variables
2. Monitor Specific Errors
// Catch all errors
window.addEventListener('error', (e) => {
console.log('Error caught:', e.message, e.filename, e.lineno);
// Send to error tracking
});
// Catch promise rejections
window.addEventListener('unhandledrejection', (e) => {
console.log('Promise rejected:', e.reason);
});
3. Filter Console Noise
// Hide specific warnings
const originalWarn = console.warn;
console.warn = (...args) => {
if (!args[0]?.includes('DevTools')) {
originalWarn.apply(console, args);
}
};
What to Look For
On Any Website
Quick health check:
- Open console
- Refresh page
- Look for:
- Red errors (broken features)
- Yellow warnings (potential issues)
- Failed network requests
- Performance violations
During Development
Before deploying:
- Zero errors in console
- No unhandled promises
- No 404s for resources
- No mixed content warnings
- No deprecation warnings
When Debugging
Follow the breadcrumbs:
[Auth] Login attempt
[API] POST /login - 200 OK
[Auth] Token received
[Router] Navigating to /dashboard
ERROR: Cannot read property 'id' of undefined
Story: Login worked, but dashboard expects user object
Production Monitoring
1. Error Tracking Services
// Sentry example
Sentry.init({
dsn: "your-dsn-here",
environment: "production"
});
2. Custom Error Logging
class ErrorLogger {
static log(error, context) {
// Send to your API
fetch('/api/errors', {
method: 'POST',
body: JSON.stringify({
message: error.message,
stack: error.stack,
context,
userAgent: navigator.userAgent,
url: window.location.href
})
});
}
}
3. User Impact Tracking
// Track errors affecting users
let errorCount = 0;
window.addEventListener('error', () => {
errorCount++;
if (errorCount > 5) {
// Show user-friendly message
showErrorBanner('Something went wrong. Please refresh.');
}
});
Console Pro Tips
1. Use Console Methods
console.table(data); // Display data as table
console.time('API call'); // Start timer
console.timeEnd('API call'); // End timer
console.group('User Flow'); // Group related logs
console.trace(); // Show stack trace
2. Conditional Logging
// Only in development
if (process.env.NODE_ENV === 'development') {
console.log('Debug info:', data);
}
// Verbose logging
const DEBUG = localStorage.getItem('debug') === 'true';
DEBUG && console.log('Detailed trace:', info);
3. Style Console Output
console.log(
'%c Success! ',
'background: #22c55e; color: white; padding: 4px 8px; border-radius: 4px;'
);
Quick Console Checklist
When visiting any site:
- Any red errors?
- Network failures?
- Security warnings?
- Performance violations?
- Deprecated features?
- Third-party errors?
When debugging:
- Error message and stack trace
- When error occurs
- What triggered it
- Browser/device specific?
- Can you reproduce it?
The Bottom Line
The console is your window into JavaScript's soul. Monitor it to:
- Catch errors before users report them
- Understand how websites work
- Debug issues faster
- Learn from others' code
Don't wait for bug reports. The console already knows.
Monitor console errors in real-time: Fusebox tracks JavaScript errors and console output while you browse. Catch issues instantly. $29 one-time purchase.