浏览器扩展,2026 年最被低估的开发方向
浏览器扩展的市场比你想的大得多——Chrome 商店有超过 20 万个扩展,但高质量、有创意的永远稀缺。而且扩展开发的学习曲线非常平缓。
我们要做什么
一个 Markdown 预览扩展:检测到 .md 文件的 URL 时,自动在页面中渲染成漂亮的 HTML。
项目结构(Manifest V3)
md-reader/
├── manifest.json
├── background.js # Service Worker
├── content.js # Content Script
├── content.css # 注入的样式
├── popup.html # 弹窗界面
├── popup.js
└── icons/
├── icon16.png
├── icon48.png
└── icon128.png
manifest.json(扩展的"身份证")
{
"manifest_version": 3,
"name": "Markdown Reader",
"version": "1.0.0",
"description": "自动渲染 .md 文件为漂亮的 HTML",
"permissions": ["storage", "activeTab"],
"host_permissions": ["*://*.github.com/*", "*://*.gitlab.com/*"],
"background": {
"service_worker": "background.js",
"type": "module"
},
"content_scripts": [{
"matches": ["*://*/*.md", "*://*/*.md?*"],
"js": ["marked.min.js", "content.js"],
"css": ["content.css"],
"run_at": "document_end"
}],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
},
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}
背景脚本(Service Worker)
// background.js
// 监听安装事件
chrome.runtime.onInstalled.addListener(({ reason }) => {
if (reason === 'install') {
chrome.storage.local.set({
theme: 'github',
fontSize: '14px'
});
}
});
// 监听来自 content script 的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'getSettings') {
chrome.storage.local.get(['theme', 'fontSize'], sendResponse);
return true; // 异步响应
}
});
核心:Content Script
// content.js
(async () => {
// 获取设置
const settings = await chrome.runtime.sendMessage({ type: 'getSettings' });
// 获取页面原始 Markdown
const md = document.body.innerText;
// 用 marked 渲染
const html = marked.parse(md);
// 替换页面内容
document.body.innerHTML = html;
// 注入样式
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = chrome.runtime.getURL('content.css');
document.head.appendChild(link);
// 注入代码高亮
document.querySelectorAll('pre code').forEach(block => {
hljs.highlightElement(block);
});
})();
发布到 Chrome 商店
# 1. 打包成 .zip
zip -r md-reader.zip md-reader/
# 2. 去 Chrome 开发者控制台
# https://chrome.google.com/webstore/devconsole
# 3. 注册(需 $5 一次性费用)
# 4. 上传 .zip
# 5. 填写商店信息:
# - 名称、描述、分类
# - 至少 1 张 1280x800 截图
# - 隐私政策 URL
# 6. 提交审核(通常 1-3 个工作日)
扩展开发的创意方向
- 生产力工具:Tab 管理、截图、翻译、鼠标手势
- 开发者工具:JSON 格式化、API 调试、设计稿对比
- 内容增强:阅读模式、暗黑模式、自动目录
- 数据采集:网页内容提取、表单自动填写
- 隐私保护:Cookie 管理、追踪器拦截
Chrome 扩展开发的优势:Web 技术栈(HTML/CSS/JS)、学习成本低、发布渠道成熟、用户获取成本低。如果你会前端,你就能做扩展。