A production-ready browser extension that will assess web page carbon emissions using Lighthouse and CO2.js APIs. The extension provides a clean, accessible side panel interface with smooth animations.
- Modern Architecture: Modular ES6 class-based design with clean separation of concerns
- Cross-Browser Support: Works seamlessly on Chrome and Firefox (Manifest V3)
- Smooth Animations: Professional slide-in/out panel with CSS transitions
- Accessible Design: WCAG-compliant interface with proper focus management
- Production Ready: Clean code with no debug output and comprehensive error handling
✅ Core Extension Complete:
- ✅ Production-ready extension architecture
- ✅ Cross-browser compatibility (Chrome & Firefox)
- ✅ Smooth animated side panel
- ✅ Reliable toggle functionality
- ✅ Modular panel system ready for expansion
- ✅ Professional UI with responsive design
- 🔄 Lighthouse API integration (ready for implementation)
- 🔄 CO2.js API integration (ready for implementation)
git clone <your-repo-url>
cd carbon-visualizer-extensionnpm installnpm run buildThis will create browser-specific builds in the build/ directory.
- Build the extension: npm run build
- Open Chrome and navigate to chrome://extensions/
- Enable "Developer mode" in the top right
- Click "Load unpacked"
- Select the build/chrome/folder
- Build the extension: npm run build
- Open Firefox and navigate to about:debugging
- Click "This Firefox" tab
- Click "Load Temporary Add-on"
- Select the manifest.jsonfile frombuild/firefox/folder
- Navigate to any website (e.g., https://example.com)
- Click the Carbon Visualizer extension icon in your toolbar
- The welcome panel should slide in smoothly from the left
- Click the extension icon again to close the panel
- Click "Analyze This Page" button to see the placeholder functionality
npm run buildThis creates:
- build/chrome/- Chrome extension files
- build/firefox/- Firefox extension files
- build/carbon-visualizer-chrome.zip- Chrome package
- build/carbon-visualizer-firefox.zip- Firefox package
carbon-visualizer-extension/
├── manifest.json              # Unified manifest for both browsers (Manifest V3)
├── background.js              # Cross-browser background script
├── content.js                 # Content script loader with duplicate prevention
├── build.js                   # Build script for both browsers
├── src/                       # Source code directory
│   ├── core/                  # Core extension classes
│   │   ├── ExtensionManager.js # Main extension manager with toggle logic
│   │   └── Panel.js           # Base panel class with animation support
│   ├── styles/                # Core styles
│   │   └── core.css           # Panel container and animation styles
│   └── panels/                # Individual panel implementations
│       └── welcome/           # Welcome panel
│           ├── welcome.html   # Welcome panel HTML structure
│           ├── welcome.css    # Welcome panel specific styles
│           └── welcome.js     # Welcome panel logic
├── icons/                     # Extension icons
│   ├── icon.svg              # Source SVG icon
│   ├── icon16.png            # 16x16 icon
│   ├── icon48.png            # 48x48 icon
│   └── icon128.png           # 128x128 icon
├── build/                     # Generated build files
│   ├── chrome/               # Chrome-specific build
│   ├── firefox/              # Firefox-specific build
│   ├── carbon-visualizer-chrome.zip   # Chrome package
│   └── carbon-visualizer-firefox.zip  # Firefox package
├── package.json               # Project configuration
└── README.md                  # This file
- ExtensionManager: Central coordinator handling panel lifecycle and message routing
- Panel: Base class for all panel types with consistent loading and animation
- Modular Panels: Each panel (welcome, loading, results) has its own HTML/CSS/JS files
- Concurrency Control: Prevents multiple simultaneous toggle operations
- State Management: DOM-based detection with cleanup-first approach
- Error Handling: Graceful fallbacks with silent error handling
- Unified Manifest: Single Manifest V3 file for both Chrome and Firefox
- Browser API Detection: Automatic detection of chromevsbrowserAPIs
- Dynamic Imports: ES6 modules with CSP compliance
- Build System: Automated packaging for both browsers
- Create loading panel for assessment progress
- Create results panel for displaying metrics
- Integrate Lighthouse API via serverless function
- Integrate CO2.js calculations
- Implement assessment workflow in ExtensionManager
- Add detailed performance breakdowns
- Include carbon reduction recommendations
- Add historical tracking and comparisons
- Implement export functionality
- Add batch analysis for multiple pages
- Include industry benchmarks
- Add customizable scoring algorithms
- Implement team collaboration features
The extension will use serverless functions (Vercel/Netlify) to handle API calls:
- Lighthouse API: Performance metrics via PageSpeed Insights API
- CO2.js: Carbon calculations using The Green Web Foundation's library
- Benefits: No API keys in client code, better security, rate limiting control
- Edit the relevant files:
- src/core/ExtensionManager.js- Main extension logic and panel coordination
- src/core/Panel.js- Base panel functionality and animations
- src/panels/welcome/- Welcome panel HTML, CSS, and JavaScript
- src/styles/core.css- Core panel styles and animations
- background.js- Background script and message handling
- content.js- Content script initialization
 
- Run npm run buildto rebuild the extension
- Go to chrome://extensions/orabout:debuggingin Firefox
- Click the refresh icon on your extension
- Reload the web page you're testing on
- Create a new directory in src/panels/(e.g.,src/panels/results/)
- Add results.html,results.css, andresults.jsfiles
- Update the getPanelConfig()method insrc/core/Panel.js
- Add panel logic to src/core/ExtensionManager.js
- Production: No console output (clean and professional)
- Development: Temporarily add console.log statements for debugging
- Use Chrome DevTools to inspect the extension and panel DOM
- Check the Extensions tab to view background script status
- ✅ Chrome (Manifest V3)
- ✅ Firefox (Manifest V3 - supported since Firefox 109)
- ✅ Edge (Manifest V3)
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Chrome Extension Development Guide
- Lighthouse API Documentation
- CO2.js Documentation
- WAVE Accessibility Tool (inspiration for UI design)
If you encounter any issues or have questions:
- Check the browser console for error messages
- Verify the extension is properly loaded in chrome://extensions/
- Ensure you're testing on a valid HTTP/HTTPS website
- Check that all required permissions are granted