Update debug endpoint to show User-Agent detection in HTML

This commit is contained in:
Keith Smith
2025-12-26 22:31:25 -07:00
parent 123d6af430
commit ea40beb408
+30 -10
View File
@@ -1,20 +1,40 @@
"""Debug views for troubleshooting mobile app."""
from django.http import JsonResponse
from django.http import JsonResponse, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
@csrf_exempt
@require_http_methods(["GET", "POST"])
def debug_user_agent(request):
"""Return the User-Agent header for debugging mobile app."""
user_agent = request.META.get('HTTP_USER_AGENT', 'No User-Agent')
return JsonResponse({
'user_agent': user_agent,
'is_mobile_app_detected': (
'CapacitorHttp' in user_agent or
'com.firebugit.keepitgoing' in user_agent or
('KeepItGoing' in user_agent and 'Mobile' in user_agent)
),
'headers': dict(request.META),
})
# Simple HTML response that's easy to see in iframe
html = f"""
<!DOCTYPE html>
<html>
<head>
<title>Debug Info</title>
<style>
body {{ font-family: monospace; padding: 20px; }}
.detected {{ color: green; font-weight: bold; }}
.not-detected {{ color: red; font-weight: bold; }}
</style>
</head>
<body>
<h2>Mobile App Debug Info</h2>
<p><strong>User-Agent:</strong><br>{user_agent}</p>
<p><strong>Contains 'wv':</strong> {'wv' in user_agent.lower()}</p>
<p><strong>Contains 'CapacitorHttp':</strong> {'CapacitorHttp' in user_agent}</p>
<p><strong>Is Mobile App Detected:</strong>
<span class="{'detected' if ('wv' in user_agent.lower() or 'CapacitorHttp' in user_agent) else 'not-detected'}">
{('wv' in user_agent.lower() or 'CapacitorHttp' in user_agent)}
</span>
</p>
</body>
</html>
"""
return HttpResponse(html)