-
manifest.json
- Start here to understand permissions and extension structure
- Key configurations for Chrome APIs
- Content script and service worker registration
-
content.js
- Handles user interactions (double-click events)
- Creates and manages popup UI
- Implements message passing with background script
-
background.js (Service Worker)
- Manages AI model interactions
- Coordinates between content script and side panel
- Handles extension lifecycle events
-
sidepanel.html & sidepanel.js
- Main interface for detailed word analysis
- Three main sections: Etymology, Usage, Synonyms
- Handles data rendering and updates
-
styles.css
- UI styling for popup and side panel
- Component-specific styles
- Animation and transition definitions
A[User Selection] --> B[content.js] B --> C[background.js] C --> D[AI Model] D --> C C --> E[sidepanel.js] E --> F[UI Update]
-
Word Selection Flow
User double-clicks word → content.js creates popup → background.js queries AI model → sidepanel.js updates UI
-
Message Passing System
content.js ↔ background.js ↔ sidepanel.js
-
State Management
- Popup state in content.js
- Loading states across components
- Side panel content management
-
Initial Setup
git clone [repository-url] cd [repository-name] # Load extension in Chrome
-
Development Environment
- Chrome DevTools for debugging
- Extension management page (
chrome://extensions
) - Enable Developer Mode
-
Testing Flow
1. Make changes 2. Reload extension 3. Test on sample pages 4. Check console for errors
- Determine component location (content/background/sidepanel)
- Update message passing if needed
- Add UI elements
- Implement error handling
- Update documentation
- Use
console.log()
in content.js for page interactions - Check background page console for service worker logs
- Monitor network requests in DevTools
- Inspect side panel using right-click → Inspect
src/ ├── manifest.json # Extension configuration ├── content.js # Page interaction logic ├── background.js # Service worker ├── sidepanel/ │ ├── sidepanel.html # Panel layout │ ├── sidepanel.js # Panel logic │ └── styles.css # Styling └── lib/ # Third-party libraries
- Word selection works across different sites
- Popup appears in correct position
- Side panel updates properly
- Error states handled gracefully
- Memory leaks checked
- Cross-browser compatibility verified
-
Message Passing
- Always check for runtime errors
- Handle disconnection cases
- Clean up listeners
-
Memory Management
- Remove event listeners when not needed
- Clear popups before creating new ones
- Monitor side panel memory usage
-
Security Considerations
- Sanitize HTML content
- Validate user input
- Follow CSP guidelines
-
Event Handling
- Debounce frequent events
- Use event delegation
- Clean up listeners
-
Resource Loading
- Lazy load when possible
- Minimize API calls
- Cache responses when appropriate
-
Content → Background
getPopupData
: Fetches initial etymologyopenSidePanel
: Triggers side panel openingcloseSidePanel
: Closes side panel
-
Background → Sidepanel
updateSidePanel
: Updates panel contentupdateLoadingStates
: Manages loading indicators
javascript // Key State Objects let currentPopup = null; // Tracks active popup let currentButton = null; // Tracks active button let messageListener = null; // Tracks message listener
-
Feature Development
1. Create feature branch 2. Implement changes 3. Test locally 4. Submit PR
-
Bug Fixes
1. Reproduce issue 2. Add console logging 3. Fix and verify 4. Add regression test
- Check message passing implementation
- Verify memory cleanup
- Review error handling
- Validate UI responsiveness
- Ensure documentation updates