1.9 KiB
1.9 KiB
Fix PWA Install Prompt Implementation Plan
Objective
Ensure the PWA install prompt appears reliably on mobile devices, addressing potential issues with event timing, iOS compatibility, and explicit Service Worker registration.
Root Causes to Address
- Late Event Listener: The
beforeinstallpromptevent might fire before the React component mounts. We need to capture it globally as early as possible. - Missing Service Worker Registration: While
vite-plugin-pwacan auto-inject, explicit registration inmain.tsxensures it's active and handles updates. - iOS Compatibility: iOS does not support
beforeinstallprompt. We must detect iOS and show specific "Share -> Add to Home Screen" instructions. - Secure Context: PWA features require HTTPS. While we can't force this on the user's network, we can ensure the app behaves best-effort and maybe warn if needed (skipped for now to avoid noise, focusing on logical fixes).
Tasks
- Update
src/client/src/main.tsx:- Import
registerSWfromvirtual:pwa-register. - Add a global
windowevent listener forbeforeinstallpromptimmediately upon script execution to capture the event. - Expose the captured event on
window(or a global store) so the React component can consume it.
- Import
- Update
src/client/src/components/PWAInstallPrompt.tsx:- Check
window.deferredInstallPrompt(or similar) on mount. - Add User Agent detection for iOS (iPhone/iPad/iPod).
- If iOS, display a custom "Add to Home Screen" instruction banner.
- If Android/Desktop, use the captured prompt.
- Check
- Docs: Update devlog.
Technical Details
- Global Property:
window.deferredInstallPrompt - iOS Detection: Regex on
navigator.userAgentlooking foriPhone|iPad|iPod(and notMSStream).
Status
- Register SW explicitly in main.tsx
- Capture
beforeinstallpromptglobally - Add iOS specific UI
- Completed: 2025-12-18