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

推荐订阅源

L
LangChain Blog
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
S
SegmentFault 最新的问题
量子位
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
博客园 - Franky
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
B
Blog RSS Feed
C
Check Point Blog
The Cloudflare Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
V
Visual Studio Blog
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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
Auto-Detecting Location in a Firefox Extension Without As...
Weather Cloc · 2026-05-04 · via DEV Community

Weather Clock Dash

Auto-Detecting Location Without Asking for GPS

For the Weather & Clock Dashboard Firefox extension, I needed the user's city without requiring the geolocation permission (which triggers a scary browser prompt).

Here is the approach I used.

The Problem with navigator.geolocation

The geolocation permission triggers a modal asking the user to share their precise location. For a new tab weather extension, this feels invasive. The user just wanted weather — they did not expect a location permission prompt.

Solution: IP-Based Geolocation

For weather purposes, city-level accuracy is enough. IP geolocation gives you the city without any user prompt:

async function getLocationFromIP() {
  const resp = await fetch("https://ipapi.co/json/");
  const data = await resp.json();
  return {
    city: data.city,
    country: data.country_name,
    timezone: data.timezone,
  };
}

Enter fullscreen mode Exit fullscreen mode

This requires no permissions, no user prompt, and works in any browser extension context.

Privacy Considerations

IP geolocation does not require you to send the user's IP to a third party — the user's browser is already making the request to get their own IP info. However, you should:

  1. Disclose this in your privacy policy
  2. Cache the result to avoid hitting the API on every new tab open
  3. Allow users to manually override their city

The Fallback: Let Users Type Their City

The most privacy-friendly approach is to let users type their own city:

// First-run setup
const { city } = await browser.storage.local.get("city");
if (!city) {
  // Show a setup screen asking for city
  showCityInput();
} else {
  loadWeather(city);
}

Enter fullscreen mode Exit fullscreen mode

This is what the Weather & Clock Dashboard does — no automatic location detection, no permissions requested. The user types their city once and it is saved locally.

Which to Choose?

Approach Accuracy Privacy UX
GPS (geolocation API) Precise Requires permission prompt Scary for new tab
IP geolocation City-level No prompt, but uses external API Seamless
Manual input User-specified No external APIs One-time setup friction

For a new tab extension where weather is secondary, manual input respects users the most. For a weather-first extension where accuracy matters, IP geolocation is the right trade-off.