我如何构建了一个隐私优先的 Firefox 新标签页扩展(永不收集数据)
I’m happy to help translate the article, but I need the full text you’d like translated. Could you please paste the content (excluding the source line you already provided) so I can convert it to Simplified Chinese while preserving the formatting and code blocks?
大多数浏览器扩展的问题
浏览器扩展存在声誉问题。许多流行的扩展——天气应用、新标签页替换、生产力工具——悄悄收集你的浏览数据,出售给广告商,或要求使用与身份关联的账户。
当我为 Firefox 构建 Weather & Clock Dashboard 时,我做了不同的选择:零数据收集、无需账户、无跟踪。下面是其技术实现方式。
什么是“隐私优先”
这个词经常被提及。对本扩展而言,它意味着:
- 不向我的服务器发起网络请求 — 天气数据直接从你的浏览器请求 Open‑Meteo 的 API
- 不收集分析或遥测数据 — 没有 Mixpanel、没有 GA4、没有 PostHog
- 无需账户 — 设置本地存储在
localStorage中,永不同步 - 最小化权限 — 仅使用
storage和geolocation(如果你启用了天气功能)
架构
[Your Browser] → [Open-Meteo API] (weather data)
[Your Browser] → [localStorage] (your settings)
That's it. No middleman.
在没有后端的情况下处理天气
大多数天气扩展会将您的位置通过它们自己的服务器转发。这使它们能够:
- 记录您的 IP 地址
- 将您的位置与账户关联
- 出售这些数据
使用 Open‑Meteo,我跳过了所有这些:
// Browser requests weather directly — no proxy server
async function fetchWeather(lat, lon) {
const url = `https://api.open-meteo.com/v1/forecast
?latitude=${lat}
&longitude=${lon}
¤t_weather=true
&daily=temperature_2m_max,temperature_2m_min,weathercode
&forecast_days=3`;
const response = await fetch(url);
return response.json();
}
Open‑Meteo 是一个免费、开源的天气 API,无需 API 密钥。您的 IP 会触及它们的服务器(任何天气服务都不可避免),但没有账户关联。
地理位置:先获取用户同意
function requestWeatherPermission() {
navigator.geolocation.getCurrentPosition(
position => {
// User approved — fetch weather
fetchWeather(position.coords.latitude, position.coords.longitude);
},
error => {
// User denied — show a default city selector
showCitySearch();
}
);
}
浏览器原生的地理位置权限对话框让用户拥有完全控制权。如果被拒绝,扩展程序会回退到城市搜索,这样您仍然可以获取天气信息,而无需共享精确位置。
设置存储:仅 localStorage
所有偏好——主题、已选择的城市、温度单位——都存储在 localStorage 中。不会发送到任何地方。
const SETTINGS_KEY = 'wcd_settings';
function saveSettings(settings) {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
}
function loadSettings() {
const raw = localStorage.getItem(SETTINGS_KEY);
return raw ? JSON.parse(raw) : DEFAULT_SETTINGS;
}
这意味着设置不会在设备之间同步——这是有意的取舍。同步需要服务器,服务器需要账户,从而会留下隐私足迹。
权限清单
{
"permissions": [
"storage"
],
"optional_permissions": [
"geolocation"
]
}
storage 用于 localStorage。geolocation 是可选的——只有在您点击“启用天气”时才会请求。将其与请求 tabs、history、browsingData 或 webNavigation 的扩展进行比较——这些权限实际上并非其核心功能所必需。
开源以实现问责
该扩展采用 MIT 许可证,源码可供审查。隐私声明容易做出,而伪造源码则很困难。
当用户可以阅读代码时,他们可以验证:
- 没有隐藏的 API 调用
- 没有混淆的跟踪代码
- 权限实际上用于其声称的用途
结果
Weather & Clock Dashboard 作为新标签页的替代品,具备以下功能:
- 实时天气和 3 天预报
- 多个时区的世界时钟
- 搜索栏(可自行选择搜索引擎)
- 暗色/亮色模式
且完全不收集任何您的数据。
Install it: Weather & Clock Dashboard on AMO
如果您正在开发浏览器扩展,请考虑采用相同的做法。用户对隐私的要求日益提升——真正以隐私为先不仅是道德要求,更是竞争优势。