| name | chrome-extension |
| description | Expert guidance for Chrome extension development with Manifest V3. Use when building Chrome extensions, browser extensions, or working with Chrome APIs. Triggers on: chrome extension, browser extension, manifest v3, chrome api, extension development. |
Chrome Extension Development
Expert guidance for Chrome extension development with Manifest V3.
Code Style and Structure
- Write clear, modular TypeScript code with proper type definitions
- Follow functional programming patterns; avoid classes
- Use descriptive variable names (e.g., isLoading, hasPermission)
- Structure files logically: popup, background, content scripts, utils
- Implement proper error handling and logging
- Document code with JSDoc comments
Architecture and Best Practices
- Strictly follow Manifest V3 specifications
- Divide responsibilities between background, content scripts and popup
- Configure permissions following the principle of least privilege
- Use modern build tools (webpack/vite) for development
- Implement proper version control and change management
Chrome API Usage
Storage
chrome.storage.local.set({ key: value });
const { key } = await chrome.storage.local.get('key');
chrome.storage.onChanged.addListener((changes, namespace) => {
if (changes.key) {
console.log('Key changed:', changes.key.newValue);
}
});
Tabs
const tab = await chrome.tabs.create({ url: 'https://example.com' });
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
await chrome.tabs.sendMessage(tabId, { action: 'update' });
Runtime (Messaging)
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'getData') {
sendResponse({ data: 'response' });
}
return true;
});
const response = await chrome.runtime.sendMessage({ action: 'getData' });
Alarms (Scheduled Tasks)
chrome.alarms.create('myAlarm', { periodInMinutes: 30 });
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'myAlarm') {
}
});
Security and Privacy
- Implement Content Security Policy (CSP)
- Handle user data securely
- Prevent XSS and injection attacks
- Use secure messaging between components
- Handle cross-origin requests safely
- Implement secure data encryption
- Follow web_accessible_resources best practices
Performance and Optimization
- Minimize resource usage and avoid memory leaks
- Optimize background script performance
- Implement proper caching mechanisms
- Handle asynchronous operations efficiently
- Monitor and optimize CPU/memory usage
Manifest V3 Structure
{
"manifest_version": 3,
"name": "My Extension",
"version": "1.0.0",
"permissions": ["storage", "activeTab"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"]
}],
"action": {
"default_popup": "popup.html"
}
}
Testing and Debugging
- Use Chrome DevTools effectively
- Write unit and integration tests
- Test cross-browser compatibility
- Monitor performance metrics
- Handle error scenarios
Publishing Checklist
Activation Keywords
chrome-extension
chrome-extension
chrome extension
Tools Used
Instructions for Agents
- Read the task description carefully
- Follow the step-by-step process
- Use the appropriate tools
- Verify the results
Examples
Example 1: Basic Usage
User:
Agent:
Example 2: Advanced Usage
User:
Agent: