Spaces:
Running
PWA on Localhost - Important Information
Summary
The PWA files were created successfully, but they won't work fully on localhost:8501 due to Streamlit's static file serving limitations.
What You're Seeing (or Not Seeing)
β What DOES Work on Localhost:
- Game functionality: Everything works normally
- Challenge Mode: Loading
?game_id=...works (if HF credentials configured) - PWA meta tags: Injected into HTML (check page source)
- Service worker registration attempt: Runs in browser console
β What DOESN'T Work on Localhost:
manifest.jsonnot accessible:http://localhost:8501/app/static/manifest.json β Returns HTML instead of JSON (Streamlit doesn't serve /app/static/)Icons not accessible:
http://localhost:8501/app/static/icon-192.png β Returns 404 or HTMLService worker fails to register:
// Browser console shows: Failed to register service worker: 404 Not FoundNo PWA install prompt:
- No banner at bottom of screen
- No install icon in address bar
- PWA features disabled
Why This Happens
Streamlit's Static File Serving:
Streamlit only serves files from:
/.streamlit/static/(internal Streamlit assets)- Component assets via
declare_component() - NOT from arbitrary
battlewords/static/directories
On HuggingFace Spaces:
/app/static/is mapped by HF infrastructure- Files in
battlewords/static/are accessible at/app/static/ - β PWA works perfectly
On localhost:
- No
/app/static/mapping exists - Streamlit returns HTML for all unrecognized paths
- β PWA files return 404
- No
How to Test PWA Locally
Option 1: Use ngrok (HTTPS Tunnel) β RECOMMENDED
This is the best way to test PWA locally with full functionality:
# Terminal 1: Run Streamlit
streamlit run app.py
# Terminal 2: Expose with HTTPS
ngrok http 8501
# Output shows:
# Forwarding https://abc123.ngrok-free.app -> http://localhost:8501
Then visit the HTTPS URL on your phone or desktop:
- β Full PWA functionality
- β Install prompt appears
- β manifest.json loads
- β Service worker registers
- β Icons display correctly
ngrok Setup:
- Download: https://ngrok.com/download
- Sign up for free account
- Install:
unzip /path/to/ngrok.zip(or chocolatey on Windows:choco install ngrok) - Authenticate:
ngrok config add-authtoken <your-token> - Run:
ngrok http 8501
Option 2: Deploy to HuggingFace Spaces β PRODUCTION
PWA works out-of-the-box on HF Spaces:
git add battlewords/static/ battlewords/ui.py
git commit -m "Add PWA support"
git push
# HF Spaces auto-deploys
# Visit: https://surn-battlewords.hf.space
Then test PWA:
- Android Chrome: "Add to Home Screen" prompt appears
- iOS Safari: Share β "Add to Home Screen"
- Desktop Chrome: Install icon in address bar
β This is where PWA is meant to work!
###Option 3: Manual Static File Server (Advanced)
You can serve the static files separately:
# Terminal 1: Run Streamlit
streamlit run app.py
# Terminal 2: Serve static files
cd battlewords/static
python3 -m http.server 8502
# Then access:
# Streamlit: http://localhost:8501
# Static files: http://localhost:8502/manifest.json
Then modify the PWA paths in ui.py:
pwa_meta_tags = """
<link rel="manifest" href="http://localhost:8502/manifest.json">
<link rel="apple-touch-icon" href="http://localhost:8502/icon-192.png">
<!-- etc -->
"""
β Not recommended: Too complex, defeats the purpose
What About Challenge Mode?
Question: "I loaded localhost:8501/?game_id=hDjsB_dl but don't see anything"
Answer: Challenge Mode is separate from PWA. You should see a blue banner at the top if:
β Requirements for Challenge Mode to Work:
Environment variables configured (
.envfile):HF_API_TOKEN=hf_xxxxxxxxxxxxx HF_REPO_ID=Surn/Storage SPACE_NAME=Surn/BattleWordsValid game_id exists in the HF repo:
hDjsB_dlmust be a real challenge created previously- Check HuggingFace dataset repo: https://huggingface.co/datasets/Surn/Storage
- Look for:
games/<uid>/settings.json - Verify
shortener.jsonhas entry forhDjsB_dl
Internet connection (to fetch challenge data)
If Challenge Mode ISN'T Working:
Check browser console (F12 β Console):
// Look for errors:
"[game_storage] Could not resolve sid: hDjsB_dl" β Challenge not found
"Failed to load game from sid" β HF API error
"HF_API_TOKEN not configured" β Missing credentials
If you see errors:
- Verify
.envfile exists with correct variables - Restart Streamlit (
Ctrl+Candstreamlit run app.pyagain) - Try a different
game_idfrom a known challenge - Check HF repo has the challenge data
Summary Table
| Feature | Localhost | Localhost + ngrok | HF Spaces (Production) |
|---|---|---|---|
| Game works | β | β | β |
| Challenge Mode | β (if .env configured) | β | β |
| PWA manifest loads | β | β | β |
| Service worker registers | β | β | β |
| Install prompt | β | β | β |
| Icons display | β | β | β |
| Full-screen mode | β | β | β |
What You Should Do
For Development:
β Just develop normally on localhost
- Game features work fine
- Challenge Mode works (if .env configured)
- PWA features won't work, but that's okay
- Test PWA when you deploy
For PWA Testing:
β Use ngrok for quick local PWA testing
- 5 minutes to setup
- Full PWA functionality
- Test on real phone
For Production:
β Deploy to HuggingFace Spaces
- PWA works automatically
- No configuration needed
/app/static/path works out-of-the-box
Bottom Line
Your question: "Should I see something at the bottom of the screen?"
Answer:
PWA install prompt: β Not on
localhost:8501(Streamlit limitation)- Will work on HF Spaces production deployment β
- Will work with ngrok HTTPS tunnel β
Challenge Mode banner: β Should appear at TOP (not bottom)
- Check if
?game_id=hDjsB_dlexists in your HF repo - Check browser console for errors
- Verify
.envhasHF_API_TOKENconfigured
- Check if
The PWA implementation is correct and ready for production. It just won't work on bare localhost due to Streamlit's static file serving limitations. Once you deploy to HuggingFace Spaces, everything will work perfectly!
Quick Test Command
# Check if .env is configured:
cat .env | grep HF_
# Should show:
# HF_API_TOKEN=hf_xxxxx
# HF_REPO_ID=Surn/Storage
# SPACE_NAME=Surn/BattleWords
# If missing, Challenge Mode won't work locally
Next Steps:
- Test game functionality on localhost β
- Deploy to HF Spaces for PWA testing β
- Or install ngrok for local PWA testing β