惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
月光博客
月光博客
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
B
Blog
博客园_首页
G
Google Developers Blog
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
5 Lessons I Learned Building a Firefox New Tab Extension ...
Weather Cloc · 2026-05-04 · via DEV Community

5 Lessons I Learned Building a Firefox New Tab Extension from Scratch

I spent the better part of a month building Weather & Clock Dashboard — a Firefox new tab extension that shows live weather, world clocks, and a search bar. No frameworks, no bundlers, just pure HTML/CSS/JS.

Here's what I wish someone had told me before I started.

1. The manifest_version: 3 Transition Is Mostly Smooth, But Watch for Service Worker Gotchas

Firefox now supports Manifest V3, and I decided to go all-in. Most things just work — declarative content scripts, the new permissions model, cleaner background handling.

But service workers have a critical limitation: they go inactive after 30 seconds. For a new tab extension that needs to refresh weather data periodically, this matters.

My solution: fetch weather data on each new tab open, not on a persistent background schedule. Yes, this means an API call every time you open a tab, but with proper caching (save to localStorage with a timestamp, refresh only if > 10 minutes old), it works great and doesn't drain the battery:

async function getWeather() {
  const cached = JSON.parse(localStorage.getItem('weatherCache') || '{}');
  const now = Date.now();

  if (cached.data && (now - cached.timestamp) < 10 * 60 * 1000) {
    return cached.data; // Use cached data
  }

  const data = await fetch(`https://api.openweathermap.org/data/2.5/weather?...`);
  localStorage.setItem('weatherCache', JSON.stringify({ data, timestamp: now }));
  return data;
}

Enter fullscreen mode Exit fullscreen mode

2. chrome_url_overrides Is Still the Right Way to Override New Tab in Firefox

Despite Firefox calling its extension API browser.*, the manifest.json key for overriding the new tab page is still chrome_url_overrides. Not browser_url_overrides.

{
  "chrome_url_overrides": {
    "newtab": "newtab.html"
  }
}

Enter fullscreen mode Exit fullscreen mode

This tripped me up for an embarrassing amount of time.

3. Geolocation in an Extension Requires Extra Permission Handling

My extension uses the user's location for weather. In a regular webpage, you'd call navigator.geolocation.getCurrentPosition(). In an extension's new tab page, this works — BUT you need to handle the case where the user denies permission.

More importantly, on first install, Firefox shows a permission prompt. If the user clicks "Block", you get exactly zero indication of what happened — the geolocation call silently fails.

My fix: use a fallback to manual city entry if geolocation fails, with a clear UI prompt explaining what happened:

navigator.geolocation.getCurrentPosition(
  (pos) => fetchWeatherByCoords(pos.coords),
  (err) => {
    // err.code === 1: User denied
    // err.code === 2: Position unavailable  
    // err.code === 3: Timeout
    showManualCityInput(err.code === 1 ? 
      'Location blocked — enter your city manually' : 
      'Could not detect location'
    );
  },
  { timeout: 5000, maximumAge: 3600000 }
);

Enter fullscreen mode Exit fullscreen mode

4. Dark Mode Detection in Extensions Is Actually Elegant

Implementing dark/light mode switching is one place where browser extensions have an advantage over regular web apps. You get prefers-color-scheme support out of the box, plus the option to persist user preference:

// Auto-detect system preference
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');

// Apply theme
function applyTheme(dark) {
  document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
  localStorage.setItem('theme', dark ? 'dark' : 'light');
}

// Listen for system changes
prefersDark.addEventListener('change', (e) => applyTheme(e.matches));

// On load: check user preference first, then system
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
  applyTheme(savedTheme === 'dark');
} else {
  applyTheme(prefersDark.matches);
}

Enter fullscreen mode Exit fullscreen mode

Users get the "just works" experience (matches their OS setting) with the option to override.

5. AMO Review Is Actually Quite Fast (and Human)

I was dreading the Firefox Add-On (AMO) review process, expecting a multi-week wait. My experience was surprisingly good:

  • Initial review: ~3 days
  • Reviewer feedback: Specific, actionable (they flagged one eval() call I hadn't noticed)
  • Follow-up review: ~1 day

The reviewer actually looked at the code. They pointed out that I was using innerHTML to set a clock time value (unnecessary DOM risk even though the data was internal), and asked me to switch to textContent. Fair point.

Things that help get through review faster:

  • Write clean, readable code
  • Minimize permissions to exactly what you need
  • No remote code execution
  • No obfuscation
  • Include source maps if you minify

The Result

After all this, I shipped Weather & Clock Dashboard — it's open source (MIT), no account required, and genuinely useful.

If you're building a Firefox extension, the developer experience is actually really solid. The API documentation has improved dramatically in the past few years, and the Mozilla developer community is helpful.

Have questions? Drop them in the comments — happy to share more specifics about the implementation.


Built with: Pure HTML/CSS/JS · No build step · MIT Licensed