From ec51db9de486be03dd87618395c446b881851f01 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Wed, 18 Mar 2026 10:09:15 +0100 Subject: [PATCH] debug(pwa): add admin-only display-mode overlay for diagnosis on mobile Shows detected display-mode, navigator.standalone, and PWA cookies as a small green text at bottom of screen. Only visible for admin users. Co-Authored-By: Claude Opus 4.6 (1M context) --- templates/base.html | 9 +++++++-- utils/analytics.py | 11 ++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/templates/base.html b/templates/base.html index cb08022..c53bf1d 100755 --- a/templates/base.html +++ b/templates/base.html @@ -2382,12 +2382,17 @@ } } if (window.navigator.standalone === true) detected = 'ios-standalone'; - // Set cookie with detected mode for debugging document.cookie = 'pwa_display=' + detected + '; path=/; max-age=86400; SameSite=Lax'; - // PWA = anything that is NOT 'browser' and NOT 'unknown' if (detected !== 'browser' && detected !== 'unknown') { document.cookie = 'pwa_mode=1; path=/; max-age=86400; SameSite=Lax'; } + {% if current_user.is_authenticated and current_user.has_role(SystemRole.ADMIN) %} + // Debug: show detected mode for admin (temporary) + var d = document.createElement('div'); + d.style.cssText = 'position:fixed;bottom:0;left:0;background:rgba(0,0,0,0.8);color:#0f0;font-size:11px;padding:4px 8px;z-index:99999;font-family:monospace;'; + d.textContent = 'display-mode: ' + detected + ' | standalone: ' + window.navigator.standalone + ' | cookies: ' + document.cookie.split(';').filter(function(c){return c.trim().startsWith('pwa')}).join(', '); + document.body.appendChild(d); + {% endif %} })(); // PWA Smart Banner logic diff --git a/utils/analytics.py b/utils/analytics.py index c948299..848aee7 100644 --- a/utils/analytics.py +++ b/utils/analytics.py @@ -98,14 +98,11 @@ def get_or_create_analytics_session(): user_session.last_activity_at = datetime.now() if current_user.is_authenticated and not user_session.user_id: user_session.user_id = current_user.id - # PWA cookie arrives on 2nd request (after JS sets it) - pwa_cookie = request.cookies.get('pwa_mode') - pwa_display = request.cookies.get('pwa_display') - if pwa_display: - logger.info(f"PWA display mode: '{pwa_display}' pwa_mode={pwa_cookie} session={user_session.id} browser={user_session.browser}") - if not user_session.is_pwa and pwa_cookie == '1': + # PWA detection from cookie (set by JS in standalone mode) + pwa_cookie = request.cookies.get('pwa_mode') == '1' + pwa_display = request.cookies.get('pwa_display', '') + if not user_session.is_pwa and pwa_cookie: user_session.is_pwa = True - logger.info(f"Setting is_pwa=True for session {user_session.id}") db.commit() return user_session.id