Geolocation doesn't work with file:// URLs!
Instead of double-clicking the HTML file, run a local server:
# Option 1: Python (simplest)
python3 -m http.server 8000
# Option 2: Node.js (if you have it)
npx http-server -p 8000Then open: http://localhost:8000/popup.html
Modern browsers block geolocation on file:// URLs for security. You need either:
http://localhost(local server)https://(deployed site)
That's why it stopped working - you probably opened it as a file instead of through a server!
Here is what the Weather App looks like:
Your weather app requires an API key from OpenWeatherMap. For security, do not commit your API key to public repositories.
How to add your API key:
-
Open
popup.jsand find the line:const API_KEY = "YOUR_API_KEY_HERE";
Replace
YOUR_API_KEY_HEREwith your actual API key. -
Save the file. Your app will now use your key for weather requests.
Note:
- Environment variables (like
.envfiles orprocess.env) do not work in pure browser JavaScript. You must hardcode the key or use extension storage/config files. - For browser extensions, you can use
chrome.storageor a config file to store secrets.
- Never share your API key publicly.
- If you publish your code, remove or replace your API key before sharing.
