#!/usr/bin/env python3 """ PWA Diagnostic Script for Talk2Me Checks common PWA installation issues """ import requests import json import sys from urllib.parse import urljoin def check_pwa(base_url): """Check PWA requirements for the given URL""" if not base_url.startswith(('http://', 'https://')): base_url = 'https://' + base_url if not base_url.endswith('/'): base_url += '/' print(f"Checking PWA for: {base_url}\n") # Check HTTPS if not base_url.startswith('https://'): print("❌ PWA requires HTTPS (except for localhost)") return else: print("✅ HTTPS is enabled") # Check main page try: response = requests.get(base_url, timeout=10) if response.status_code == 200: print("✅ Main page loads successfully") else: print(f"❌ Main page returned status code: {response.status_code}") except Exception as e: print(f"❌ Error loading main page: {e}") return # Check manifest manifest_url = urljoin(base_url, '/static/manifest.json') print(f"\nChecking manifest at: {manifest_url}") try: response = requests.get(manifest_url, timeout=10) if response.status_code == 200: print("✅ Manifest file found") # Parse manifest try: manifest = response.json() print(f" - Name: {manifest.get('name', 'Not set')}") print(f" - Short name: {manifest.get('short_name', 'Not set')}") print(f" - Display: {manifest.get('display', 'Not set')}") print(f" - Start URL: {manifest.get('start_url', 'Not set')}") print(f" - Icons: {len(manifest.get('icons', []))} defined") # Check icons for icon in manifest.get('icons', []): icon_url = urljoin(base_url, icon['src']) try: icon_response = requests.head(icon_url, timeout=5) if icon_response.status_code == 200: print(f" ✅ {icon['sizes']}: {icon['src']}") else: print(f" ❌ {icon['sizes']}: {icon['src']} (Status: {icon_response.status_code})") except: print(f" ❌ {icon['sizes']}: {icon['src']} (Failed to load)") except json.JSONDecodeError: print("❌ Manifest is not valid JSON") else: print(f"❌ Manifest returned status code: {response.status_code}") except Exception as e: print(f"❌ Error loading manifest: {e}") # Check service worker sw_url = urljoin(base_url, '/service-worker.js') print(f"\nChecking service worker at: {sw_url}") try: response = requests.get(sw_url, timeout=10) if response.status_code == 200: print("✅ Service worker file found") content_type = response.headers.get('Content-Type', '') if 'javascript' in content_type: print("✅ Service worker has correct content type") else: print(f"⚠️ Service worker content type: {content_type}") else: print(f"❌ Service worker returned status code: {response.status_code}") except Exception as e: print(f"❌ Error loading service worker: {e}") # Check favicon favicon_url = urljoin(base_url, '/static/icons/favicon.ico') print(f"\nChecking favicon at: {favicon_url}") try: response = requests.head(favicon_url, timeout=5) if response.status_code == 200: print("✅ Favicon found") else: print(f"⚠️ Favicon returned status code: {response.status_code}") except Exception as e: print(f"⚠️ Error loading favicon: {e}") print("\n" + "="*50) print("PWA Installation Tips:") print("1. Clear browser cache and app data") print("2. Visit the site in Chrome on Android") print("3. Wait a few seconds for the install prompt") print("4. Or tap menu (⋮) → 'Add to Home screen'") print("5. Check Chrome DevTools → Application → Manifest") print("="*50) if __name__ == "__main__": if len(sys.argv) > 1: url = sys.argv[1] else: url = input("Enter the URL to check (e.g., talk2me.dr74.net): ") check_pwa(url)