extension-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExtension Dev
Chrome扩展开发
Detect the stack, find docs, implement the feature, debug. Do NOT just explain — execute the workflow.
检测技术栈、查找文档、实现功能、调试。请勿仅做解释——请执行以下工作流程。
Workflow (Execute This)
工作流程(请执行以下步骤)
Step 1: Detect framework and UI stack
步骤1:检测框架与UI技术栈
Run detection (see ):
references/framework-detection.mdbash
ls wxt.config.ts plasmo.config.ts vite.config.ts manifest.json 2>/dev/null
cat package.json | grep -E '"wxt|plasmo|crxjs|react|vue|svelte"'| File found | Framework |
|---|---|
| WXT |
| Plasmo |
| CRXJS |
| Vanilla |
运行检测脚本(详见):
references/framework-detection.mdbash
ls wxt.config.ts plasmo.config.ts vite.config.ts manifest.json 2>/dev/null
cat package.json | grep -E '"wxt|plasmo|crxjs|react|vue|svelte"'| 找到的文件 | 框架 |
|---|---|
| WXT |
| Plasmo |
| CRXJS |
根目录下有 | 原生(Vanilla) |
Step 2: Fetch framework docs and style guides
步骤2:获取框架文档与风格指南
Use skill or web search to find proper docs for the detected stack.
docs-seekerExtension framework docs:
- WXT: https://wxt.dev/ | Plasmo: https://docs.plasmo.com/ | CRXJS: Vite plugin docs
- Chrome APIs: https://developer.chrome.com/docs/extensions/reference/api
- Permissions: https://developer.chrome.com/docs/extensions/reference/permissions-list
UI framework docs (fetch based on detected framework):
Code style guides (always follow):
- TypeScript: https://google.github.io/styleguide/tsguide.html
- JavaScript: https://google.github.io/styleguide/jsguide.html
使用技能或网页搜索,为检测到的技术栈查找合适的文档。
docs-seeker扩展框架文档:
- WXT: https://wxt.dev/ | Plasmo: https://docs.plasmo.com/ | CRXJS: Vite插件文档
- Chrome APIs: https://developer.chrome.com/docs/extensions/reference/api
- 权限列表: https://developer.chrome.com/docs/extensions/reference/permissions-list
UI框架文档(根据检测到的框架获取):
代码风格指南(必须遵循):
- TypeScript: https://google.github.io/styleguide/tsguide.html
- JavaScript: https://google.github.io/styleguide/jsguide.html
Step 3: Implement the feature
步骤3:实现功能
Follow framework conventions:
- WXT: add entrypoints in , configure
entrypoints/wxt.config.ts - Plasmo: add pages/tabs/contents, use CSUI for content UI
- CRXJS: standard Vite + manifest-based setup
- Vanilla: edit , add JS files directly
manifest.json
For Chrome API usage, check .
For messaging between contexts, check .
references/chrome-api-quick-reference.mdreferences/message-passing-patterns.md遵循框架约定:
- WXT: 在目录下添加入口文件,配置
entrypoints/wxt.config.ts - Plasmo: 添加pages/tabs/contents,使用CSUI构建内容UI
- CRXJS: 标准Vite + 基于manifest的配置
- 原生(Vanilla): 编辑,直接添加JS文件
manifest.json
关于Chrome API的使用,请查看。
关于上下文间的消息传递,请查看。
references/chrome-api-quick-reference.mdreferences/message-passing-patterns.mdStep 4: Debug
步骤4:调试
See for context-specific DevTools access.
references/debugging-guide.mdQuick map:
| Context | How to inspect |
|---|---|
| Service worker | |
| Content script | Page DevTools → Console → select extension context |
| Popup | Right-click popup → Inspect |
| Options / Side panel | Open page → F12 |
查看获取各上下文环境的DevTools访问方法。
references/debugging-guide.md快速指南:
| 上下文环境 | 检查方法 |
|---|---|
| Service worker | |
| Content script | 页面DevTools → 控制台 → 选择扩展上下文 |
| Popup | 右键点击popup → 检查 |
| 选项 / 侧边栏 | 打开页面 → 按F12 |
Step 5: Hot reload setup
步骤5:热重载配置
| Framework | Command | Notes |
|---|---|---|
| WXT | | Full HMR, auto-reloads extension |
| Plasmo | | HMR for popup/content |
| CRXJS | | Vite HMR |
| Vanilla | Manual | Reload at |
| 框架 | 命令 | 说明 |
|---|---|---|
| WXT | | 完整HMR,自动重载扩展 |
| Plasmo | | 支持popup/content的HMR |
| CRXJS | | Vite HMR |
| 原生(Vanilla) | 手动操作 | 在 |
Chrome API Quick Reference (Top 20)
Chrome API速查(Top 20)
| API | Purpose | Permission |
|---|---|---|
| Query, create, update tabs | |
| Manage browser windows | |
| Persist data locally | |
| Sync data across devices | |
| Session-only data | |
| Toolbar icon, popup, badge | — |
| Right-click menu items | |
| Side panel UI | |
| Desktop notifications | |
| Inject scripts/CSS into pages | |
| Messaging, lifecycle, manifest | — |
| Intercept/modify network requests | |
| Block/redirect requests declaratively | |
| Track page navigation events | |
| OAuth2, Google Sign-In | |
| Schedule periodic tasks | |
| Keyboard shortcuts | |
| Read/write cookies | |
| Browser history access | |
| Read/write bookmarks | |
| API | 用途 | 权限 |
|---|---|---|
| 查询、创建、更新标签页 | |
| 管理浏览器窗口 | |
| 本地持久化存储数据 | |
| 跨设备同步数据 | |
| 会话级临时数据存储 | |
| 工具栏图标、popup、徽章 | — |
| 右键菜单项 | |
| 侧边栏UI | |
| 桌面通知 | |
| 向页面注入脚本/CSS | |
| 消息传递、生命周期、manifest | — |
| 拦截/修改网络请求 | |
| 声明式阻止/重定向请求 | |
| 跟踪页面导航事件 | |
| OAuth2、Google登录 | |
| 调度周期性任务 | |
| 键盘快捷键 | |
| 读写Cookie | |
| 访问浏览器历史 | |
| 读写书签 | |
Message Passing (Quick Pattern)
消息传递(快速模式)
One-time (popup → service worker):
ts
// sender
const response = await chrome.runtime.sendMessage({ type: 'GET_DATA' });
// receiver (background)
chrome.runtime.onMessage.addListener((msg, sender, reply) => {
if (msg.type === 'GET_DATA') { reply({ data: '...' }); return true; }
});Content script → service worker: same pattern, for async.
Tab-targeted (background → content):
return truets
chrome.tabs.sendMessage(tabId, { type: 'ACTION' });Full patterns in .
references/message-passing-patterns.md一次性消息(popup → service worker):
ts
// 发送方
const response = await chrome.runtime.sendMessage({ type: 'GET_DATA' });
// 接收方(后台)
chrome.runtime.onMessage.addListener((msg, sender, reply) => {
if (msg.type === 'GET_DATA') { reply({ data: '...' }); return true; }
});Content script → service worker: 模式相同,异步场景需。
定向标签页(后台 → content):
return truets
chrome.tabs.sendMessage(tabId, { type: 'ACTION' });完整模式请查看。
references/message-passing-patterns.mdReferences
参考资料
- — detect WXT/Plasmo/CRXJS/vanilla, dev commands
references/framework-detection.md - — UI framework docs, style guides, extension framework docs
references/framework-styleguides.md - — 30+ APIs with permissions and doc links
references/chrome-api-quick-reference.md - — all messaging patterns with TypeScript examples
references/message-passing-patterns.md - — DevTools per context, common errors, tips
references/debugging-guide.md
- — 检测WXT/Plasmo/CRXJS/原生扩展,开发命令
references/framework-detection.md - — UI框架文档、风格指南、扩展框架文档
references/framework-styleguides.md - — 30+个API,包含权限与文档链接
references/chrome-api-quick-reference.md - — 所有消息传递模式,附TypeScript示例
references/message-passing-patterns.md - — 各上下文环境的DevTools使用、常见错误与技巧
references/debugging-guide.md
Related Skills
相关技能
- — scaffold new extension with WXT
extension-create - — generate/validate manifest.json
extension-manifest - — write and run extension tests
extension-test - — analyze existing extension codebase
extension-analyze
- — 使用WXT快速搭建新扩展
extension-create - — 生成/验证manifest.json
extension-manifest - — 编写并运行扩展测试
extension-test - — 分析现有扩展代码库
extension-analyze