Skip to content

A sleek React component for capturing and copying console output with an elegant hover-to-expand UI

Notifications You must be signed in to change notification settings

mariov96/fetch-dev-console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FetchDevConsole

npm version License: MIT

A sleek, lightweight React component that captures and displays console output with an elegant hover-to-expand UI. Perfect for debugging, error reporting, and streamlined development workflows. Designed to be added to page headers for quick developer access to crucial console information.

✨ Features

  • 🎯 Smart Console Interception: Automatically captures all console output (log, error, warn, info, debug)
  • πŸ” Intelligent Filtering: Built-in suppression for common third-party library warnings
  • πŸ“‹ One-Click Copy: Copy console output to clipboard with rich context information
  • 🎨 Elegant UI: Minimalist floating button that expands on hover
  • 🏷️ Visual Indicators: Badge showing error/warning counts with color coding
  • ⚑ Zero Configuration: Works out of the box with sensible defaults
  • πŸ”§ Highly Customizable: Position, theme, size, and suppression patterns
  • πŸ“¦ Lightweight: Minimal bundle size impact
  • 🎭 Framework Agnostic Core: Console capture works anywhere, React UI optional
  • πŸš€ Header Integration: Perfect for adding to page headers for persistent developer access

πŸš€ Quick Start

NPM Installation

npm install fetch-dev-console

Install the required Material-UI dependencies:

npm install @mui/material @emotion/react @emotion/styled @mui/icons-material
import React from 'react';
import { FetchDevConsole, initConsoleCapture } from 'fetch-dev-console';

// Initialize console capture (call once in your app)
initConsoleCapture();

function App() {
  return (
    <div>
      <header>
        <h1>My App</h1>
        {/* Add to header for persistent developer access */}
        {process.env.NODE_ENV === 'development' && <FetchDevConsole />}
      </header>
      {/* Your app content */}
    </div>
  );
}

export default App;

πŸ”§ Integration with Existing Projects

Using Git Subtree (Recommended)

Perfect for integrating into existing React projects while maintaining the ability to receive updates:

# ⚠️ Important: Ensure your working tree is clean before adding subtree
git status  # Check for uncommitted changes
git add .   # Stage any changes
git commit -m "Save current work before adding fetch-dev-console"

# Add fetch-dev-console as a subtree
git subtree add --prefix=src/components/fetch-dev-console https://github.com/mariov96/fetch-dev-console.git main --squash

Usage after subtree integration:

// Import from your local subtree
import { FetchDevConsole, initConsoleCapture } from './components/fetch-dev-console/src';

// Initialize in your main App component
function App() {
  useEffect(() => {
    initConsoleCapture();
  }, []);

  return (
    <div>
      <header className="app-header">
        <nav>Your Navigation</nav>
        {/* Add to header for quick developer access */}
        {process.env.NODE_ENV === 'development' && (
          <FetchDevConsole position="top-right" />
        )}
      </header>
      {/* Your app content */}
    </div>
  );
}

Future Updates:

# Pull updates from the fetch-dev-console repo
git subtree pull --prefix=src/components/fetch-dev-console https://github.com/mariov96/fetch-dev-console.git main --squash

Alternative: Manual Installation

If you prefer not to use git subtree:

# Clone to temporary location
git clone https://github.com/mariov96/fetch-dev-console.git temp-console
mkdir -p src/components/fetch-dev-console
cp -r temp-console/* src/components/fetch-dev-console/
rm -rf temp-console

# Install Material-UI dependencies if not already installed
npm install @mui/material @emotion/react @emotion/styled @mui/icons-material

# Add to your project
git add src/components/fetch-dev-console/
git commit -m "Add fetch-dev-console component"

Header Integration Best Practices

// Layout component with header integration
function Layout({ children }) {
  return (
    <div className="app-layout">
      <header className="main-header">
        <div className="header-content">
          <Logo />
          <Navigation />
          {/* Developer console access in header */}
          {process.env.NODE_ENV === 'development' && (
            <div className="dev-tools">
              <FetchDevConsole 
                position="top-right"
                theme="auto"
                size="medium"
              />
            </div>
          )}
        </div>
      </header>
      <main>{children}</main>
    </div>
  );
}

Troubleshooting Integration

  • "fatal: working tree has modifications": Commit or stash your changes before running git subtree add
  • Component not found: Check the import path matches your actual file structure
  • Styles not loading: Ensure CSS imports are included in your build process
  • Material-UI errors: Make sure all required MUI dependencies are installed: @mui/material, @emotion/react, @emotion/styled, @mui/icons-material
  • Console not capturing: Make sure initConsoleCapture() is called before any console output

🎨 Demo

FetchDevConsole Demo

Hover to expand, click to copy, dropdown for filtering options

πŸ“– API Reference

initConsoleCapture(options?)

Initialize the console capture system. Call this once in your application root.

Options:

  • suppressPatterns?: string[] - Array of patterns to suppress from console
  • maxLogs?: number - Maximum logs to keep in memory (default: 1000)
initConsoleCapture({
  suppressPatterns: [
    'react-beautiful-dnd',
    'Support for defaultProps will be removed',
    'Your custom warning pattern'
  ],
  maxLogs: 500
});

<FetchDevConsole /> Component

Props:

  • position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' - Button position
  • theme?: 'light' | 'dark' | 'auto' - Color theme
  • size?: 'small' | 'medium' | 'large' - Button size
<FetchDevConsole 
  position="top-right"
  theme="dark"
  size="large"
/>

testConsoleCapture()

Generate test console messages for testing the capture system.

import { testConsoleCapture } from 'fetch-dev-console';

const handleTest = () => {
  testConsoleCapture();
};

πŸ’‘ Use Cases

  • πŸ› Bug Reports: Easily copy console output to include in bug reports
  • πŸ‘¨β€πŸ’» Development: Quick access to console messages without opening DevTools
  • πŸŽ“ Education: Teaching and demonstrating console behavior
  • πŸ”§ Support: Help users provide console output for troubleshooting
  • πŸ“Š Monitoring: Track console activity during development
  • πŸ—οΈ Header Integration: Persistent developer access across all pages

🎯 Advanced Usage

Custom Styling & Positioning

// Top-left dark theme, large size for header placement
<FetchDevConsole 
  position="top-left"
  theme="dark"
  size="large"
/>

Framework-Agnostic Usage

// Use console capture without React
import { initConsoleCapture } from 'fetch-dev-console';

initConsoleCapture({
  suppressPatterns: ['unwanted-warning'],
  maxLogs: 200
});

// Access captured logs
console.log(window.consoleCapture.logs);

// Copy programmatically
await window.copyAllConsole(true); // errors only

Development vs Production

The component is designed to be included only in development builds:

// Automatic exclusion from production
{process.env.NODE_ENV === 'development' && <FetchDevConsole />}

// Or with custom environment logic
{(isDevelopment || isStaging) && <FetchDevConsole />}

This ensures it's automatically excluded from production bundles while providing crucial debugging access during development.

πŸ› οΈ Development

# Clone the repository
git clone https://github.com/mariov96/fetch-dev-console.git
cd fetch-dev-console

# Install dependencies
npm install

# Start development mode
npm run dev

# Build for production
npm run build

πŸ“„ License

MIT Β© Mario Vaccari

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

⭐ Show your support

Give a ⭐️ if this project helped you!


Made with ❀️ by Mario Vaccari

About

A sleek React component for capturing and copying console output with an elegant hover-to-expand UI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published