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 .…